Browse Source

Merge branch 'dev' into refactor-worker

pull/2/head
dailidong 4 years ago committed by GitHub
parent
commit
3c05ae8f20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 103
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java
  2. 96
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java
  3. 180
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataSourceController.java
  4. 75
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java
  5. 28
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoggerController.java
  6. 21
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoginController.java
  7. 45
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/MonitorController.java
  8. 220
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java
  9. 161
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java
  10. 102
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java
  11. 97
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/QueueController.java
  12. 465
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java
  13. 104
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java
  14. 33
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java
  15. 28
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskRecordController.java
  16. 108
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TenantController.java
  17. 209
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java
  18. 60
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java
  19. 3
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandler.java
  20. 12
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandlerTest.java
  21. 14
      dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/instance/pages/gantt/_source/gantt.js

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

@ -16,6 +16,7 @@
*/ */
package org.apache.dolphinscheduler.api.controller; 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.service.AlertGroupService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
@ -37,13 +38,15 @@ import springfox.documentation.annotations.ApiIgnore;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.apache.dolphinscheduler.api.enums.Status.*;
/** /**
* alert group controller * alert group controller
*/ */
@Api(tags = "ALERT_GROUP_TAG", position = 1) @Api(tags = "ALERT_GROUP_TAG", position = 1)
@RestController @RestController
@RequestMapping("alert-group") @RequestMapping("alert-group")
public class AlertGroupController extends BaseController{ public class AlertGroupController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(AlertGroupController.class); private static final Logger logger = LoggerFactory.getLogger(AlertGroupController.class);
@ -53,53 +56,47 @@ public class AlertGroupController extends BaseController{
/** /**
* create alert group * create alert group
*
* @param loginUser login user * @param loginUser login user
* @param groupName group name * @param groupName group name
* @param groupType group type * @param groupType group type
* @param description description * @param description description
* @return create result code * @return create result code
*/ */
@ApiOperation(value = "createAlertgroup", notes= "CREATE_ALERT_GROUP_NOTES") @ApiOperation(value = "createAlertgroup", notes = "CREATE_ALERT_GROUP_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType ="AlertType"), @ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType = "AlertType"),
@ApiImplicitParam(name = "description", value = "DESC", dataType ="String") @ApiImplicitParam(name = "description", value = "DESC", dataType = "String")
}) })
@PostMapping(value = "/create") @PostMapping(value = "/create")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_ALERT_GROUP_ERROR)
public Result createAlertgroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result createAlertgroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "groupName") String groupName, @RequestParam(value = "groupName") String groupName,
@RequestParam(value = "groupType") AlertType groupType, @RequestParam(value = "groupType") AlertType groupType,
@RequestParam(value = "description",required = false) String description) { @RequestParam(value = "description", required = false) String description) {
logger.info("loginUser user {}, create alertgroup, groupName: {}, groupType: {}, desc: {}", logger.info("loginUser user {}, create alertgroup, groupName: {}, groupType: {}, desc: {}",
loginUser.getUserName(), groupName, groupType,description); loginUser.getUserName(), groupName, groupType, description);
try { Map<String, Object> result = alertGroupService.createAlertgroup(loginUser, groupName, groupType, description);
Map<String, Object> result = alertGroupService.createAlertgroup(loginUser, groupName, groupType,description);
return returnDataList(result); return returnDataList(result);
}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());
}
} }
/** /**
* alert group list * alert group list
*
* @param loginUser login user * @param loginUser login user
* @return alert group list * @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") @GetMapping(value = "/list")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_ALL_ALERTGROUP_ERROR)
public Result list(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { public Result list(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
logger.info("login user {}, query all alertGroup", logger.info("login user {}, query all alertGroup",
loginUser.getUserName()); loginUser.getUserName());
try {
HashMap<String, Object> result = alertGroupService.queryAlertgroup(); HashMap<String, Object> result = alertGroupService.queryAlertgroup();
return returnDataList(result); 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());
}
} }
/** /**
@ -111,37 +108,34 @@ public class AlertGroupController extends BaseController{
* @param pageSize page size * @param pageSize page size
* @return alert group list page * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type ="String"), @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"),
@ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"), @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"),
@ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20") @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20")
}) })
@GetMapping(value="/list-paging") @GetMapping(value = "/list-paging")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(LIST_PAGING_ALERT_GROUP_ERROR)
public Result listPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result listPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageSize") Integer pageSize){ @RequestParam("pageSize") Integer pageSize) {
logger.info("login user {}, list paging, pageNo: {}, searchVal: {}, pageSize: {}", logger.info("login user {}, list paging, pageNo: {}, searchVal: {}, pageSize: {}",
loginUser.getUserName(),pageNo,searchVal,pageSize); loginUser.getUserName(), pageNo, searchVal, pageSize);
try{
Map<String, Object> result = checkPageParams(pageNo, pageSize); Map<String, Object> result = checkPageParams(pageNo, pageSize);
if(result.get(Constants.STATUS) != Status.SUCCESS){ if (result.get(Constants.STATUS) != Status.SUCCESS) {
return returnDataListPaging(result); return returnDataListPaging(result);
} }
searchVal = ParameterUtils.handleEscapes(searchVal); searchVal = ParameterUtils.handleEscapes(searchVal);
result = alertGroupService.listPaging(loginUser, searchVal, pageNo, pageSize); result = alertGroupService.listPaging(loginUser, searchVal, pageNo, pageSize);
return returnDataListPaging(result); 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());
}
} }
/** /**
* updateProcessInstance alert group * updateProcessInstance alert group
*
* @param loginUser login user * @param loginUser login user
* @param id alert group id * @param id alert group id
* @param groupName group name * @param groupName group name
@ -149,75 +143,67 @@ public class AlertGroupController extends BaseController{
* @param description description * @param description description
* @return update result code * @return update result code
*/ */
@ApiOperation(value = "updateAlertgroup", notes= "UPDATE_ALERT_GROUP_NOTES") @ApiOperation(value = "updateAlertgroup", notes = "UPDATE_ALERT_GROUP_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "ALERT_GROUP_ID", required = true, dataType = "Int",example = "100"), @ApiImplicitParam(name = "id", value = "ALERT_GROUP_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType ="AlertType"), @ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType = "AlertType"),
@ApiImplicitParam(name = "description", value = "DESC", dataType ="String") @ApiImplicitParam(name = "description", value = "DESC", dataType = "String")
}) })
@PostMapping(value = "/update") @PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_ALERT_GROUP_ERROR)
public Result updateAlertgroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result updateAlertgroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int id, @RequestParam(value = "id") int id,
@RequestParam(value = "groupName") String groupName, @RequestParam(value = "groupName") String groupName,
@RequestParam(value = "groupType") AlertType groupType, @RequestParam(value = "groupType") AlertType groupType,
@RequestParam(value = "description",required = false) String description) { @RequestParam(value = "description", required = false) String description) {
logger.info("login user {}, updateProcessInstance alertgroup, groupName: {}, groupType: {}, desc: {}", logger.info("login user {}, updateProcessInstance alertgroup, groupName: {}, groupType: {}, desc: {}",
loginUser.getUserName(), groupName, groupType,description); loginUser.getUserName(), groupName, groupType, description);
try {
Map<String, Object> result = alertGroupService.updateAlertgroup(loginUser, id, groupName, groupType, description); Map<String, Object> result = alertGroupService.updateAlertgroup(loginUser, id, groupName, groupType, description);
return returnDataList(result); return returnDataList(result);
}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());
}
} }
/** /**
* delete alert group by id * delete alert group by id
*
* @param loginUser login user * @param loginUser login user
* @param id alert group id * @param id alert group id
* @return delete result code * @return delete result code
*/ */
@ApiOperation(value = "delAlertgroupById", notes= "DELETE_ALERT_GROUP_BY_ID_NOTES") @ApiOperation(value = "delAlertgroupById", notes = "DELETE_ALERT_GROUP_BY_ID_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "ALERT_GROUP_ID", required = true, dataType = "Int",example = "100") @ApiImplicitParam(name = "id", value = "ALERT_GROUP_ID", required = true, dataType = "Int", example = "100")
}) })
@PostMapping(value = "/delete") @PostMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_ALERT_GROUP_ERROR)
public Result delAlertgroupById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, 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); logger.info("login user {}, delete AlertGroup, id: {},", loginUser.getUserName(), id);
try {
Map<String, Object> result = alertGroupService.delAlertgroupById(loginUser, id); Map<String, Object> result = alertGroupService.delAlertgroupById(loginUser, id);
return returnDataList(result); 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());
}
} }
/** /**
* check alert group exist * check alert group exist
*
* @param loginUser login user * @param loginUser login user
* @param groupName group name * @param groupName group name
* @return check result code * @return check result code
*/ */
@ApiOperation(value = "verifyGroupName", notes= "VERIFY_ALERT_GROUP_NAME_NOTES") @ApiOperation(value = "verifyGroupName", notes = "VERIFY_ALERT_GROUP_NAME_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"),
}) })
@GetMapping(value = "/verify-group-name") @GetMapping(value = "/verify-group-name")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
public Result verifyGroupName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, 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); logger.info("login user {}, verify group name: {}", loginUser.getUserName(), groupName);
boolean exist= alertGroupService.existGroupName(groupName); boolean exist = alertGroupService.existGroupName(groupName);
Result result = new Result(); Result result = new Result();
if (exist) { if (exist) {
logger.error("group {} has exist, can't create again.", groupName); logger.error("group {} has exist, can't create again.", groupName);
@ -238,24 +224,19 @@ public class AlertGroupController extends BaseController{
* @param alertgroupId alert group id * @param alertgroupId alert group id
* @return grant result code * @return grant result code
*/ */
@ApiOperation(value = "grantUser", notes= "GRANT_ALERT_GROUP_NOTES") @ApiOperation(value = "grantUser", notes = "GRANT_ALERT_GROUP_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "ALERT_GROUP_ID", required = true, dataType = "Int",example = "100"), @ApiImplicitParam(name = "id", value = "ALERT_GROUP_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "userIds", value = "USER_IDS", required = true, dataType = "String") @ApiImplicitParam(name = "userIds", value = "USER_IDS", required = true, dataType = "String")
}) })
@PostMapping(value = "/grant-user") @PostMapping(value = "/grant-user")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(ALERT_GROUP_GRANT_USER_ERROR)
public Result grantUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result grantUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "alertgroupId") int alertgroupId, @RequestParam(value = "alertgroupId") int alertgroupId,
@RequestParam(value = "userIds") String userIds) { @RequestParam(value = "userIds") String userIds) {
logger.info("login user {}, grant user, alertGroupId: {},userIds : {}", loginUser.getUserName(), alertgroupId,userIds); logger.info("login user {}, grant user, alertGroupId: {},userIds : {}", loginUser.getUserName(), alertgroupId, userIds);
try {
Map<String, Object> result = alertGroupService.grantUser(loginUser, alertgroupId, userIds); Map<String, Object> result = alertGroupService.grantUser(loginUser, alertgroupId, userIds);
return returnDataList(result); 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());
}
} }
} }

96
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java

@ -17,6 +17,7 @@
package org.apache.dolphinscheduler.api.controller; 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.service.DataAnalysisService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
@ -25,7 +26,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.dolphinscheduler.api.enums.Status;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -35,13 +35,15 @@ import springfox.documentation.annotations.ApiIgnore;
import java.util.Map; import java.util.Map;
import static org.apache.dolphinscheduler.api.enums.Status.*;
/** /**
* data analysis controller * data analysis controller
*/ */
@Api(tags = "DATA_ANALYSIS_TAG", position = 1) @Api(tags = "DATA_ANALYSIS_TAG", position = 1)
@RestController @RestController
@RequestMapping("projects/analysis") @RequestMapping("projects/analysis")
public class DataAnalysisController extends BaseController{ public class DataAnalysisController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(DataAnalysisController.class); private static final Logger logger = LoggerFactory.getLogger(DataAnalysisController.class);
@ -58,27 +60,23 @@ public class DataAnalysisController extends BaseController{
* @param projectId project id * @param projectId project id
* @return task instance count data * @return task instance count data
*/ */
@ApiOperation(value = "countTaskState", notes= "COUNT_TASK_STATE_NOTES") @ApiOperation(value = "countTaskState", notes = "COUNT_TASK_STATE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "startDate", value = "START_DATE", dataType = "String"), @ApiImplicitParam(name = "startDate", value = "START_DATE", dataType = "String"),
@ApiImplicitParam(name = "endDate", value = "END_DATE", dataType ="String"), @ApiImplicitParam(name = "endDate", value = "END_DATE", dataType = "String"),
@ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType ="Int", example = "100") @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100")
}) })
@GetMapping(value="/task-state-count") @GetMapping(value = "/task-state-count")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(TASK_INSTANCE_STATE_COUNT_ERROR)
public Result countTaskState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result countTaskState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value="startDate", required=false) String startDate, @RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value="endDate", required=false) String endDate, @RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value="projectId", required=false, defaultValue = "0") int projectId){ @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) {
try{
logger.info("count task state, user:{}, start date: {}, end date:{}, project id {}", logger.info("count task state, user:{}, start date: {}, end date:{}, project id {}",
loginUser.getUserName(), startDate, endDate, projectId); loginUser.getUserName(), startDate, endDate, projectId);
Map<String, Object> result = dataAnalysisService.countTaskStateByProject(loginUser,projectId, startDate, endDate); Map<String, Object> result = dataAnalysisService.countTaskStateByProject(loginUser, projectId, startDate, endDate);
return returnDataList(result); 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());
}
} }
/** /**
@ -90,27 +88,23 @@ public class DataAnalysisController extends BaseController{
* @param projectId project id * @param projectId project id
* @return process instance data * @return process instance data
*/ */
@ApiOperation(value = "countProcessInstanceState", notes= "COUNT_PROCESS_INSTANCE_NOTES") @ApiOperation(value = "countProcessInstanceState", notes = "COUNT_PROCESS_INSTANCE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "startDate", value = "START_DATE", dataType = "String"), @ApiImplicitParam(name = "startDate", value = "START_DATE", dataType = "String"),
@ApiImplicitParam(name = "endDate", value = "END_DATE", dataType ="String"), @ApiImplicitParam(name = "endDate", value = "END_DATE", dataType = "String"),
@ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType ="Int", example = "100") @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100")
}) })
@GetMapping(value="/process-state-count") @GetMapping(value = "/process-state-count")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(COUNT_PROCESS_INSTANCE_STATE_ERROR)
public Result countProcessInstanceState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result countProcessInstanceState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value="startDate", required=false) String startDate, @RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value="endDate", required=false) String endDate, @RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value="projectId", required=false, defaultValue = "0") int projectId){ @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) {
try{
logger.info("count process instance state, user:{}, start date: {}, end date:{}, project id:{}", logger.info("count process instance state, user:{}, start date: {}, end date:{}, project id:{}",
loginUser.getUserName(), startDate, endDate, projectId); loginUser.getUserName(), startDate, endDate, projectId);
Map<String, Object> result = dataAnalysisService.countProcessInstanceStateByProject(loginUser, projectId, startDate, endDate); Map<String, Object> result = dataAnalysisService.countProcessInstanceStateByProject(loginUser, projectId, startDate, endDate);
return returnDataList(result); 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());
}
} }
/** /**
@ -120,23 +114,19 @@ public class DataAnalysisController extends BaseController{
* @param projectId project id * @param projectId project id
* @return definition count in 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({ @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) @ResponseStatus(HttpStatus.OK)
@ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
public Result countDefinitionByUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result countDefinitionByUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value="projectId", required=false, defaultValue = "0") int projectId){ @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) {
try{
logger.info("count process definition , user:{}, project id:{}", logger.info("count process definition , user:{}, project id:{}",
loginUser.getUserName(), projectId); loginUser.getUserName(), projectId);
Map<String, Object> result = dataAnalysisService.countDefinitionByUser(loginUser, projectId); Map<String, Object> result = dataAnalysisService.countDefinitionByUser(loginUser, projectId);
return returnDataList(result); 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());
}
} }
@ -149,27 +139,23 @@ public class DataAnalysisController extends BaseController{
* @param projectId project id * @param projectId project id
* @return command state in 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({ @ApiImplicitParams({
@ApiImplicitParam(name = "startDate", value = "START_DATE", dataType = "String"), @ApiImplicitParam(name = "startDate", value = "START_DATE", dataType = "String"),
@ApiImplicitParam(name = "endDate", value = "END_DATE", dataType ="String"), @ApiImplicitParam(name = "endDate", value = "END_DATE", dataType = "String"),
@ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType ="Int", example = "100") @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100")
}) })
@GetMapping(value="/command-state-count") @GetMapping(value = "/command-state-count")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(COMMAND_STATE_COUNT_ERROR)
public Result countCommandState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result countCommandState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value="startDate", required=false) String startDate, @RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value="endDate", required=false) String endDate, @RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value="projectId", required=false, defaultValue = "0") int projectId){ @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) {
try{
logger.info("count command state, user:{}, start date: {}, end date:{}, project id {}", logger.info("count command state, user:{}, start date: {}, end date:{}, project id {}",
loginUser.getUserName(), startDate, endDate, projectId); loginUser.getUserName(), startDate, endDate, projectId);
Map<String, Object> result = dataAnalysisService.countCommandState(loginUser, projectId, startDate, endDate); Map<String, Object> result = dataAnalysisService.countCommandState(loginUser, projectId, startDate, endDate);
return returnDataList(result); 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());
}
} }
/** /**
@ -179,23 +165,19 @@ public class DataAnalysisController extends BaseController{
* @param projectId project id * @param projectId project id
* @return queue state count * @return queue state count
*/ */
@ApiOperation(value = "countQueueState", notes= "COUNT_QUEUE_STATE_NOTES") @ApiOperation(value = "countQueueState", notes = "COUNT_QUEUE_STATE_NOTES")
@ApiImplicitParams({ @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) @ResponseStatus(HttpStatus.OK)
@ApiException(QUEUE_COUNT_ERROR)
public Result countQueueState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result countQueueState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value="projectId", required=false, defaultValue = "0") int projectId){ @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) {
try{
logger.info("count command state, user:{}, project id {}", logger.info("count command state, user:{}, project id {}",
loginUser.getUserName(), projectId); loginUser.getUserName(), projectId);
Map<String, Object> result = dataAnalysisService.countQueueState(loginUser, projectId); Map<String, Object> result = dataAnalysisService.countQueueState(loginUser, projectId);
return returnDataList(result); 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());
}
} }

180
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.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.dolphinscheduler.api.enums.Status; 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.service.DataSourceService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
@ -39,6 +40,7 @@ import springfox.documentation.annotations.ApiIgnore;
import java.util.Map; import java.util.Map;
import static org.apache.dolphinscheduler.api.enums.Status.*; import static org.apache.dolphinscheduler.api.enums.Status.*;
/** /**
* data source controller * data source controller
*/ */
@ -54,6 +56,7 @@ public class DataSourceController extends BaseController {
/** /**
* create data source * create data source
*
* @param loginUser login user * @param loginUser login user
* @param name data source name * @param name data source name
* @param note data source description * @param note data source description
@ -67,21 +70,22 @@ public class DataSourceController extends BaseController {
* @param other other arguments * @param other other arguments
* @return create result code * @return create result code
*/ */
@ApiOperation(value = "createDataSource", notes= "CREATE_DATA_SOURCE_NOTES") @ApiOperation(value = "createDataSource", notes = "CREATE_DATA_SOURCE_NOTES")
@ApiImplicitParams({ @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 = "note", value = "DATA_SOURCE_NOTE", dataType = "String"),
@ApiImplicitParam(name = "type", value = "DB_TYPE", required = true,dataType ="DbType"), @ApiImplicitParam(name = "type", value = "DB_TYPE", required = true, dataType = "DbType"),
@ApiImplicitParam(name = "host", value = "DATA_SOURCE_HOST",required = true, dataType ="String"), @ApiImplicitParam(name = "host", value = "DATA_SOURCE_HOST", required = true, dataType = "String"),
@ApiImplicitParam(name = "port", value = "DATA_SOURCE_PORT",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 = "database", value = "DATABASE_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "userName", value = "USER_NAME",required = true, dataType ="String"), @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "password", value = "PASSWORD", dataType ="String"), @ApiImplicitParam(name = "password", value = "PASSWORD", dataType = "String"),
@ApiImplicitParam(name = "connectType", value = "CONNECT_TYPE", dataType = "DbConnectType"), @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") @PostMapping(value = "/create")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_DATASOURCE_ERROR)
public Result createDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result createDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("name") String name, @RequestParam("name") String name,
@RequestParam(value = "note", required = false) String note, @RequestParam(value = "note", required = false) String note,
@ -96,15 +100,9 @@ public class DataSourceController extends BaseController {
@RequestParam(value = "other") String other) { @RequestParam(value = "other") String other) {
logger.info("login user {} create datasource name: {}, note: {}, type: {}, host: {}, port: {}, database : {}, principal: {}, userName : {}, connectType: {}, 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); 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); String parameter = dataSourceService.buildParameter(name, note, type, host, port, database, principal, userName, password, connectType, other);
Map<String, Object> result = dataSourceService.createDataSource(loginUser, name, note, type, parameter); Map<String, Object> result = dataSourceService.createDataSource(loginUser, name, note, type, parameter);
return returnDataList(result); 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());
}
} }
@ -125,22 +123,23 @@ public class DataSourceController extends BaseController {
* @param password password * @param password password
* @return update result code * @return update result code
*/ */
@ApiOperation(value = "updateDataSource", notes= "UPDATE_DATA_SOURCE_NOTES") @ApiOperation(value = "updateDataSource", notes = "UPDATE_DATA_SOURCE_NOTES")
@ApiImplicitParams({ @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"),
@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 = "note", value = "DATA_SOURCE_NOTE", dataType = "String"),
@ApiImplicitParam(name = "type", value = "DB_TYPE", required = true,dataType ="DbType"), @ApiImplicitParam(name = "type", value = "DB_TYPE", required = true, dataType = "DbType"),
@ApiImplicitParam(name = "host", value = "DATA_SOURCE_HOST",required = true, dataType ="String"), @ApiImplicitParam(name = "host", value = "DATA_SOURCE_HOST", required = true, dataType = "String"),
@ApiImplicitParam(name = "port", value = "DATA_SOURCE_PORT",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 = "database", value = "DATABASE_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "userName", value = "USER_NAME",required = true, dataType ="String"), @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "password", value = "PASSWORD", dataType ="String"), @ApiImplicitParam(name = "password", value = "PASSWORD", dataType = "String"),
@ApiImplicitParam(name = "connectType", value = "CONNECT_TYPE", dataType = "DbConnectType"), @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") @PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_DATASOURCE_ERROR)
public Result updateDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result updateDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("id") int id, @RequestParam("id") int id,
@RequestParam("name") String name, @RequestParam("name") String name,
@ -156,16 +155,9 @@ public class DataSourceController extends BaseController {
@RequestParam(value = "other") String other) { @RequestParam(value = "other") String other) {
logger.info("login user {} updateProcessInstance datasource name: {}, note: {}, type: {}, connectType: {}, other: {}", logger.info("login user {} updateProcessInstance datasource name: {}, note: {}, type: {}, connectType: {}, other: {}",
loginUser.getUserName(), 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);
String parameter = dataSourceService.buildParameter(name, note, type, host, port, database,principal, userName, password, connectType, other);
Map<String, Object> dataSource = dataSourceService.updateDataSource(id, loginUser, name, note, type, parameter); Map<String, Object> dataSource = dataSourceService.updateDataSource(id, loginUser, name, note, type, parameter);
return returnDataList(dataSource); return returnDataList(dataSource);
} catch (Exception e) {
logger.error(UPDATE_DATASOURCE_ERROR.getMsg(),e);
return error(UPDATE_DATASOURCE_ERROR.getCode(), UPDATE_DATASOURCE_ERROR.getMsg());
}
} }
/** /**
@ -175,26 +167,20 @@ public class DataSourceController extends BaseController {
* @param id datasource id * @param id datasource id
* @return data source detail * @return data source detail
*/ */
@ApiOperation(value = "queryDataSource", notes= "QUERY_DATA_SOURCE_NOTES") @ApiOperation(value = "queryDataSource", notes = "QUERY_DATA_SOURCE_NOTES")
@ApiImplicitParams({ @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") @PostMapping(value = "/update-ui")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_DATASOURCE_ERROR)
public Result queryDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("id") int id) { @RequestParam("id") int id) {
logger.info("login user {}, query datasource: {}", logger.info("login user {}, query datasource: {}",
loginUser.getUserName(), id); loginUser.getUserName(), id);
try {
Map<String, Object> result = dataSourceService.queryDataSource(id); Map<String, Object> result = dataSourceService.queryDataSource(id);
return returnDataList(result); 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());
}
} }
/** /**
@ -204,21 +190,17 @@ public class DataSourceController extends BaseController {
* @param type data source type * @param type data source type
* @return data source list page * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "type", value = "DB_TYPE", required = true,dataType ="DbType") @ApiImplicitParam(name = "type", value = "DB_TYPE", required = true, dataType = "DbType")
}) })
@GetMapping(value = "/list") @GetMapping(value = "/list")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_DATASOURCE_ERROR)
public Result queryDataSourceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryDataSourceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("type") DbType type) { @RequestParam("type") DbType type) {
try {
Map<String, Object> result = dataSourceService.queryDataSourceList(loginUser, type.ordinal()); Map<String, Object> result = dataSourceService.queryDataSourceList(loginUser, type.ordinal());
return returnDataList(result); 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());
}
} }
/** /**
@ -230,19 +212,19 @@ public class DataSourceController extends BaseController {
* @param pageSize page size * @param pageSize page size
* @return data source list page * @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({ @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 = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"),
@ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType ="Int",example = "20") @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20")
}) })
@GetMapping(value = "/list-paging") @GetMapping(value = "/list-paging")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_DATASOURCE_ERROR)
public Result queryDataSourceListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryDataSourceListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) { @RequestParam("pageSize") Integer pageSize) {
try {
Map<String, Object> result = checkPageParams(pageNo, pageSize); Map<String, Object> result = checkPageParams(pageNo, pageSize);
if (result.get(Constants.STATUS) != Status.SUCCESS) { if (result.get(Constants.STATUS) != Status.SUCCESS) {
return returnDataListPaging(result); return returnDataListPaging(result);
@ -250,10 +232,6 @@ public class DataSourceController extends BaseController {
searchVal = ParameterUtils.handleEscapes(searchVal); searchVal = ParameterUtils.handleEscapes(searchVal);
result = dataSourceService.queryDataSourceListPaging(loginUser, searchVal, pageNo, pageSize); result = dataSourceService.queryDataSourceListPaging(loginUser, searchVal, pageNo, pageSize);
return returnDataListPaging(result); return returnDataListPaging(result);
} catch (Exception e) {
logger.error(QUERY_DATASOURCE_ERROR.getMsg(),e);
return error(QUERY_DATASOURCE_ERROR.getCode(), QUERY_DATASOURCE_ERROR.getMsg());
}
} }
/** /**
@ -272,21 +250,22 @@ public class DataSourceController extends BaseController {
* @param password password * @param password password
* @return connect result code * @return connect result code
*/ */
@ApiOperation(value = "connectDataSource", notes= "CONNECT_DATA_SOURCE_NOTES") @ApiOperation(value = "connectDataSource", notes = "CONNECT_DATA_SOURCE_NOTES")
@ApiImplicitParams({ @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 = "note", value = "DATA_SOURCE_NOTE", dataType = "String"),
@ApiImplicitParam(name = "type", value = "DB_TYPE", required = true,dataType ="DbType"), @ApiImplicitParam(name = "type", value = "DB_TYPE", required = true, dataType = "DbType"),
@ApiImplicitParam(name = "host", value = "DATA_SOURCE_HOST",required = true, dataType ="String"), @ApiImplicitParam(name = "host", value = "DATA_SOURCE_HOST", required = true, dataType = "String"),
@ApiImplicitParam(name = "port", value = "DATA_SOURCE_PORT",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 = "database", value = "DATABASE_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "userName", value = "USER_NAME",required = true, dataType ="String"), @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "password", value = "PASSWORD", dataType ="String"), @ApiImplicitParam(name = "password", value = "PASSWORD", dataType = "String"),
@ApiImplicitParam(name = "connectType", value = "CONNECT_TYPE", dataType = "DbConnectType"), @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") @PostMapping(value = "/connect")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(CONNECT_DATASOURCE_FAILURE)
public Result connectDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result connectDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("name") String name, @RequestParam("name") String name,
@RequestParam(value = "note", required = false) String note, @RequestParam(value = "note", required = false) String note,
@ -301,7 +280,6 @@ public class DataSourceController extends BaseController {
@RequestParam(value = "other") String other) { @RequestParam(value = "other") String other) {
logger.info("login user {}, connect datasource: {} failure, note: {}, type: {}, connectType: {}, other: {}", logger.info("login user {}, connect datasource: {} failure, note: {}, type: {}, connectType: {}, other: {}",
loginUser.getUserName(), 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); String parameter = dataSourceService.buildParameter(name, note, type, host, port, database, principal, userName, password, connectType, other);
Boolean isConnection = dataSourceService.checkConnection(type, parameter); Boolean isConnection = dataSourceService.checkConnection(type, parameter);
Result result = new Result(); Result result = new Result();
@ -312,10 +290,6 @@ public class DataSourceController extends BaseController {
putMsg(result, CONNECT_DATASOURCE_FAILURE); putMsg(result, CONNECT_DATASOURCE_FAILURE);
} }
return result; return result;
} catch (Exception e) {
logger.error(CONNECT_DATASOURCE_FAILURE.getMsg(),e);
return error(CONNECT_DATASOURCE_FAILURE.getCode(), CONNECT_DATASOURCE_FAILURE.getMsg());
}
} }
/** /**
@ -325,17 +299,17 @@ public class DataSourceController extends BaseController {
* @param id data source id * @param id data source id
* @return connect result code * @return connect result code
*/ */
@ApiOperation(value = "connectionTest", notes= "CONNECT_DATA_SOURCE_TEST_NOTES") @ApiOperation(value = "connectionTest", notes = "CONNECT_DATA_SOURCE_TEST_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "DATA_SOURCE_ID", required = true, dataType ="Int", example = "100") @ApiImplicitParam(name = "id", value = "DATA_SOURCE_ID", required = true, dataType = "Int", example = "100")
}) })
@GetMapping(value = "/connect-by-id") @GetMapping(value = "/connect-by-id")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(CONNECTION_TEST_FAILURE)
public Result connectionTest(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result connectionTest(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("id") int id) { @RequestParam("id") int id) {
logger.info("connection test, login user:{}, id:{}", loginUser.getUserName(), id); logger.info("connection test, login user:{}, id:{}", loginUser.getUserName(), id);
try {
Boolean isConnection = dataSourceService.connectionTest(loginUser, id); Boolean isConnection = dataSourceService.connectionTest(loginUser, id);
Result result = new Result(); Result result = new Result();
@ -345,11 +319,6 @@ public class DataSourceController extends BaseController {
putMsg(result, CONNECTION_TEST_FAILURE); putMsg(result, CONNECTION_TEST_FAILURE);
} }
return result; return result;
} catch (Exception e) {
logger.error(CONNECTION_TEST_FAILURE.getMsg(),e);
return error(CONNECTION_TEST_FAILURE.getCode(), CONNECTION_TEST_FAILURE.getMsg());
}
} }
/** /**
@ -359,21 +328,17 @@ public class DataSourceController extends BaseController {
* @param id datasource id * @param id datasource id
* @return delete result * @return delete result
*/ */
@ApiOperation(value = "delete", notes= "DELETE_DATA_SOURCE_NOTES") @ApiOperation(value = "delete", notes = "DELETE_DATA_SOURCE_NOTES")
@ApiImplicitParams({ @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") @GetMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_DATA_SOURCE_FAILURE)
public Result delete(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result delete(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("id") int id) { @RequestParam("id") int id) {
try {
logger.info("delete datasource,login user:{}, id:{}", loginUser.getUserName(), id); logger.info("delete datasource,login user:{}, id:{}", loginUser.getUserName(), id);
return dataSourceService.delete(loginUser, 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());
}
} }
/** /**
@ -383,26 +348,21 @@ public class DataSourceController extends BaseController {
* @param name data source name * @param name data source name
* @return true if data source name not exists.otherwise return false * @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({ @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") @GetMapping(value = "/verify-name")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(VERIFY_DATASOURCE_NAME_FAILURE)
public Result verifyDataSourceName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result verifyDataSourceName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "name") String name @RequestParam(value = "name") String name
) { ) {
logger.info("login user {}, verfiy datasource name: {}", logger.info("login user {}, verfiy datasource name: {}",
loginUser.getUserName(), name); loginUser.getUserName(), name);
try {
return dataSourceService.verifyDataSourceName(loginUser, name); 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());
} }
}
/** /**
@ -412,23 +372,19 @@ public class DataSourceController extends BaseController {
* @param userId user id * @param userId user id
* @return unauthed data source result code * @return unauthed data source result code
*/ */
@ApiOperation(value = "unauthDatasource", notes= "UNAUTHORIZED_DATA_SOURCE_NOTES") @ApiOperation(value = "unauthDatasource", notes = "UNAUTHORIZED_DATA_SOURCE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType ="Int", example = "100") @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100")
}) })
@GetMapping(value = "/unauth-datasource") @GetMapping(value = "/unauth-datasource")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(UNAUTHORIZED_DATASOURCE)
public Result unauthDatasource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result unauthDatasource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("userId") Integer userId) { @RequestParam("userId") Integer userId) {
try {
logger.info("unauthorized datasource, login user:{}, unauthorized userId:{}", logger.info("unauthorized datasource, login user:{}, unauthorized userId:{}",
loginUser.getUserName(), userId); loginUser.getUserName(), userId);
Map<String, Object> result = dataSourceService.unauthDatasource(loginUser, userId); Map<String, Object> result = dataSourceService.unauthDatasource(loginUser, userId);
return returnDataList(result); return returnDataList(result);
} catch (Exception e) {
logger.error(UNAUTHORIZED_DATASOURCE.getMsg(),e);
return error(UNAUTHORIZED_DATASOURCE.getCode(), UNAUTHORIZED_DATASOURCE.getMsg());
}
} }
@ -439,23 +395,19 @@ public class DataSourceController extends BaseController {
* @param userId user id * @param userId user id
* @return authorized result code * @return authorized result code
*/ */
@ApiOperation(value = "authedDatasource", notes= "AUTHORIZED_DATA_SOURCE_NOTES") @ApiOperation(value = "authedDatasource", notes = "AUTHORIZED_DATA_SOURCE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType ="Int", example = "100") @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100")
}) })
@GetMapping(value = "/authed-datasource") @GetMapping(value = "/authed-datasource")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(AUTHORIZED_DATA_SOURCE)
public Result authedDatasource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result authedDatasource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("userId") Integer userId) { @RequestParam("userId") Integer userId) {
try {
logger.info("authorized data source, login user:{}, authorized useId:{}", logger.info("authorized data source, login user:{}, authorized useId:{}",
loginUser.getUserName(), userId); loginUser.getUserName(), userId);
Map<String, Object> result = dataSourceService.authedDatasource(loginUser, userId); Map<String, Object> result = dataSourceService.authedDatasource(loginUser, userId);
return returnDataList(result); return returnDataList(result);
} catch (Exception e) {
logger.error(AUTHORIZED_DATA_SOURCE.getMsg(),e);
return error(AUTHORIZED_DATA_SOURCE.getCode(), AUTHORIZED_DATA_SOURCE.getMsg());
}
} }
/** /**
@ -464,17 +416,13 @@ public class DataSourceController extends BaseController {
* @param loginUser login user * @param loginUser login user
* @return user info data * @return user info data
*/ */
@ApiOperation(value = "getKerberosStartupState", notes= "GET_USER_INFO_NOTES") @ApiOperation(value = "getKerberosStartupState", notes = "GET_USER_INFO_NOTES")
@GetMapping(value="/kerberos-startup-state") @GetMapping(value = "/kerberos-startup-state")
@ResponseStatus(HttpStatus.OK) @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()); logger.info("login user {}", loginUser.getUserName());
try{
// if upload resource is HDFS and kerberos startup is true , else false // if upload resource is HDFS and kerberos startup is true , else false
return success(Status.SUCCESS.getMsg(), CommonUtils.getKerberosStartupState()); 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());
}
} }
} }

75
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.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.service.ExecutorService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
@ -32,8 +32,11 @@ import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import java.text.ParseException;
import java.util.Map; import java.util.Map;
import static org.apache.dolphinscheduler.api.enums.Status.*;
/** /**
* execute process controller * execute process controller
@ -50,6 +53,7 @@ public class ExecutorController extends BaseController {
/** /**
* execute process instance * execute process instance
*
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectName project name
* @param processDefinitionId process definition id * @param processDefinitionId process definition id
@ -68,25 +72,26 @@ public class ExecutorController extends BaseController {
* @param timeout timeout * @param timeout timeout
* @return start process result code * @return start process result code
*/ */
@ApiOperation(value = "startProcessInstance", notes= "RUN_PROCESS_INSTANCE_NOTES") @ApiOperation(value = "startProcessInstance", notes = "RUN_PROCESS_INSTANCE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "scheduleTime", value = "SCHEDULE_TIME", required = true, dataType = "String"), @ApiImplicitParam(name = "scheduleTime", value = "SCHEDULE_TIME", required = true, dataType = "String"),
@ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", required = true, dataType ="FailureStrategy"), @ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", required = true, dataType = "FailureStrategy"),
@ApiImplicitParam(name = "startNodeList", value = "START_NODE_LIST", dataType ="String"), @ApiImplicitParam(name = "startNodeList", value = "START_NODE_LIST", dataType = "String"),
@ApiImplicitParam(name = "taskDependType", value = "TASK_DEPEND_TYPE", dataType ="TaskDependType"), @ApiImplicitParam(name = "taskDependType", value = "TASK_DEPEND_TYPE", dataType = "TaskDependType"),
@ApiImplicitParam(name = "execType", value = "COMMAND_TYPE", dataType ="CommandType"), @ApiImplicitParam(name = "execType", value = "COMMAND_TYPE", dataType = "CommandType"),
@ApiImplicitParam(name = "warningType", value = "WARNING_TYPE",required = true, dataType ="WarningType"), @ApiImplicitParam(name = "warningType", value = "WARNING_TYPE", required = true, dataType = "WarningType"),
@ApiImplicitParam(name = "warningGroupId", value = "WARNING_GROUP_ID",required = true, dataType ="Int", example = "100"), @ApiImplicitParam(name = "warningGroupId", value = "WARNING_GROUP_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "receivers", value = "RECEIVERS",dataType ="String" ), @ApiImplicitParam(name = "receivers", value = "RECEIVERS", dataType = "String"),
@ApiImplicitParam(name = "receiversCc", value = "RECEIVERS_CC",dataType ="String" ), @ApiImplicitParam(name = "receiversCc", value = "RECEIVERS_CC", dataType = "String"),
@ApiImplicitParam(name = "runMode", value = "RUN_MODE",dataType ="RunMode" ), @ApiImplicitParam(name = "runMode", value = "RUN_MODE", dataType = "RunMode"),
@ApiImplicitParam(name = "processInstancePriority", value = "PROCESS_INSTANCE_PRIORITY", required = true, dataType = "Priority" ), @ApiImplicitParam(name = "processInstancePriority", value = "PROCESS_INSTANCE_PRIORITY", required = true, dataType = "Priority"),
@ApiImplicitParam(name = "workerGroup", value = "WORKER_GROUP", dataType = "String",example = "default"), @ApiImplicitParam(name = "workerGroup", value = "WORKER_GROUP", dataType = "String", example = "default"),
@ApiImplicitParam(name = "timeout", value = "TIMEOUT", dataType = "Int",example = "100"), @ApiImplicitParam(name = "timeout", value = "TIMEOUT", dataType = "Int", example = "100"),
}) })
@PostMapping(value = "start-process-instance") @PostMapping(value = "start-process-instance")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(START_PROCESS_INSTANCE_ERROR)
public Result startProcessInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result startProcessInstance(@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(value = "processDefinitionId") int processDefinitionId, @RequestParam(value = "processDefinitionId") int processDefinitionId,
@ -102,13 +107,12 @@ public class ExecutorController extends BaseController {
@RequestParam(value = "runMode", required = false) RunMode runMode, @RequestParam(value = "runMode", required = false) RunMode runMode,
@RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority, @RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority,
@RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, @RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup,
@RequestParam(value = "timeout", required = false) Integer timeout) { @RequestParam(value = "timeout", required = false) Integer timeout) throws ParseException {
try {
logger.info("login user {}, start process instance, project name: {}, process definition id: {}, schedule time: {}, " logger.info("login user {}, start process instance, project name: {}, process definition id: {}, schedule time: {}, "
+ "failure policy: {}, node name: {}, node dep: {}, notify type: {}, " + "failure policy: {}, node name: {}, node dep: {}, notify type: {}, "
+ "notify group id: {},receivers:{},receiversCc:{}, run mode: {},process instance priority:{}, workerGroup: {}, timeout: {}", + "notify group id: {},receivers:{},receiversCc:{}, run mode: {},process instance priority:{}, workerGroup: {}, timeout: {}",
loginUser.getUserName(), projectName, processDefinitionId, scheduleTime, loginUser.getUserName(), projectName, processDefinitionId, scheduleTime,
failureStrategy, startNodeList, taskDependType, warningType, workerGroup,receivers,receiversCc,runMode,processInstancePriority, failureStrategy, startNodeList, taskDependType, warningType, workerGroup, receivers, receiversCc, runMode, processInstancePriority,
workerGroup, timeout); workerGroup, timeout);
if (timeout == null) { if (timeout == null) {
@ -117,12 +121,8 @@ public class ExecutorController extends BaseController {
Map<String, Object> result = execService.execProcessInstance(loginUser, projectName, processDefinitionId, scheduleTime, execType, failureStrategy, Map<String, Object> result = execService.execProcessInstance(loginUser, projectName, processDefinitionId, scheduleTime, execType, failureStrategy,
startNodeList, taskDependType, warningType, startNodeList, taskDependType, warningType,
warningGroupId,receivers,receiversCc, runMode,processInstancePriority, workerGroup, timeout); warningGroupId, receivers, receiversCc, runMode, processInstancePriority, workerGroup, timeout);
return returnDataList(result); 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());
}
} }
@ -135,27 +135,23 @@ public class ExecutorController extends BaseController {
* @param executeType execute type * @param executeType execute type
* @return execute result code * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "executeType", value = "EXECUTE_TYPE", required = true, dataType = "ExecuteType") @ApiImplicitParam(name = "executeType", value = "EXECUTE_TYPE", required = true, dataType = "ExecuteType")
}) })
@PostMapping(value = "/execute") @PostMapping(value = "/execute")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(EXECUTE_PROCESS_INSTANCE_ERROR)
public Result execute(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result execute(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
@RequestParam("processInstanceId") Integer processInstanceId, @RequestParam("processInstanceId") Integer processInstanceId,
@RequestParam("executeType") ExecuteType executeType @RequestParam("executeType") ExecuteType executeType
) { ) {
try {
logger.info("execute command, login user: {}, project:{}, process instance id:{}, execute type:{}", logger.info("execute command, login user: {}, project:{}, process instance id:{}, execute type:{}",
loginUser.getUserName(), projectName, processInstanceId, executeType); loginUser.getUserName(), projectName, processInstanceId, executeType);
Map<String, Object> result = execService.execute(loginUser, projectName, processInstanceId, executeType); Map<String, Object> result = execService.execute(loginUser, projectName, processInstanceId, executeType);
return returnDataList(result); return returnDataList(result);
} 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());
}
} }
/** /**
@ -165,23 +161,18 @@ public class ExecutorController extends BaseController {
* @param processDefinitionId process definition id * @param processDefinitionId process definition id
* @return check result code * @return check result code
*/ */
@ApiOperation(value = "startCheckProcessDefinition", notes= "START_CHECK_PROCESS_DEFINITION_NOTES") @ApiOperation(value = "startCheckProcessDefinition", notes = "START_CHECK_PROCESS_DEFINITION_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100") @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100")
}) })
@PostMapping(value = "/start-check") @PostMapping(value = "/start-check")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(CHECK_PROCESS_DEFINITION_ERROR)
public Result startCheckProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, 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); logger.info("login user {}, check process definition {}", loginUser.getUserName(), processDefinitionId);
try {
Map<String, Object> result = execService.startCheckByProcessDefinedId(processDefinitionId); Map<String, Object> result = execService.startCheckByProcessDefinedId(processDefinitionId);
return returnDataList(result); 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());
}
} }
/** /**
@ -193,7 +184,7 @@ public class ExecutorController extends BaseController {
* @return receivers cc list * @return receivers cc list
*/ */
@ApiIgnore @ApiIgnore
@ApiOperation(value = "getReceiverCc", notes= "GET_RECEIVER_CC_NOTES") @ApiOperation(value = "getReceiverCc", notes = "GET_RECEIVER_CC_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_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") @GetMapping(value = "/get-receiver-cc")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_RECIPIENTS_AND_COPYERS_BY_PROCESS_DEFINITION_ERROR)
public Result getReceiverCc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result getReceiverCc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "processDefinitionId",required = false) Integer processDefinitionId, @RequestParam(value = "processDefinitionId", required = false) Integer processDefinitionId,
@RequestParam(value = "processInstanceId",required = false) Integer processInstanceId) { @RequestParam(value = "processInstanceId", required = false) Integer processInstanceId) {
logger.info("login user {}, get process definition receiver and cc", loginUser.getUserName()); logger.info("login user {}, get process definition receiver and cc", loginUser.getUserName());
try { Map<String, Object> result = execService.getReceiverCc(processDefinitionId, processInstanceId);
Map<String, Object> result = execService.getReceiverCc(processDefinitionId,processInstanceId);
return returnDataList(result); 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());
}
} }

28
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoggerController.java

@ -17,6 +17,7 @@
package org.apache.dolphinscheduler.api.controller; 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.service.LoggerService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
@ -25,7 +26,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.dolphinscheduler.api.enums.Status;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -35,6 +35,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import static org.apache.dolphinscheduler.api.enums.Status.*;
/** /**
* log controller * log controller
@ -52,33 +54,29 @@ public class LoggerController extends BaseController {
/** /**
* query task log * query task log
*
* @param loginUser login user * @param loginUser login user
* @param taskInstanceId task instance id * @param taskInstanceId task instance id
* @param skipNum skip number * @param skipNum skip number
* @param limit limit * @param limit limit
* @return task log content * @return task log content
*/ */
@ApiOperation(value = "queryLog", notes= "QUERY_TASK_INSTANCE_LOG_NOTES") @ApiOperation(value = "queryLog", notes = "QUERY_TASK_INSTANCE_LOG_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "taskInstanceId", value = "TASK_ID", dataType = "Int", example = "100"), @ApiImplicitParam(name = "taskInstanceId", value = "TASK_ID", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "skipLineNum", value = "SKIP_LINE_NUM", 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 = "limit", value = "LIMIT", dataType = "Int", example = "100")
}) })
@GetMapping(value = "/detail") @GetMapping(value = "/detail")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_TASK_INSTANCE_LOG_ERROR)
public Result queryLog(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryLog(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "taskInstanceId") int taskInstanceId, @RequestParam(value = "taskInstanceId") int taskInstanceId,
@RequestParam(value = "skipLineNum") int skipNum, @RequestParam(value = "skipLineNum") int skipNum,
@RequestParam(value = "limit") int limit) { @RequestParam(value = "limit") int limit) {
try {
logger.info( logger.info(
"login user {}, view {} task instance log ,skipLineNum {} , limit {}", loginUser.getUserName(), taskInstanceId, skipNum, limit); "login user {}, view {} task instance log ,skipLineNum {} , limit {}", loginUser.getUserName(), taskInstanceId, skipNum, limit);
return loggerService.queryLog(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());
}
} }
@ -89,24 +87,20 @@ public class LoggerController extends BaseController {
* @param taskInstanceId task instance id * @param taskInstanceId task instance id
* @return log file content * @return log file content
*/ */
@ApiOperation(value = "downloadTaskLog", notes= "DOWNLOAD_TASK_INSTANCE_LOG_NOTES") @ApiOperation(value = "downloadTaskLog", notes = "DOWNLOAD_TASK_INSTANCE_LOG_NOTES")
@ApiImplicitParams({ @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") @GetMapping(value = "/download-log")
@ResponseBody @ResponseBody
@ApiException(DOWNLOAD_TASK_INSTANCE_LOG_FILE_ERROR)
public ResponseEntity downloadTaskLog(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public ResponseEntity downloadTaskLog(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "taskInstanceId") int taskInstanceId) { @RequestParam(value = "taskInstanceId") int taskInstanceId) {
try {
byte[] logBytes = loggerService.getLogBytes(taskInstanceId); byte[] logBytes = loggerService.getLogBytes(taskInstanceId);
return ResponseEntity return ResponseEntity
.ok() .ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + System.currentTimeMillis() + ".log" + "\"") .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + System.currentTimeMillis() + ".log" + "\"")
.body(logBytes); .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());
}
} }
} }

21
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.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.security.Authenticator; import org.apache.dolphinscheduler.api.security.Authenticator;
import org.apache.dolphinscheduler.api.service.SessionService; import org.apache.dolphinscheduler.api.service.SessionService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
@ -42,7 +43,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.*;
/** /**
* user login controller * user login controller
* * <p>
* swagger bootstrap ui docs refer : https://doc.xiaominfo.com/guide/enh-func.html * swagger bootstrap ui docs refer : https://doc.xiaominfo.com/guide/enh-func.html
*/ */
@Api(tags = "LOGIN_TAG", position = 1) @Api(tags = "LOGIN_TAG", position = 1)
@ -69,18 +70,17 @@ public class LoginController extends BaseController {
* @param response response * @param response response
* @return login result * @return login result
*/ */
@ApiOperation(value = "login", notes= "LOGIN_NOTES") @ApiOperation(value = "login", notes = "LOGIN_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, dataType = "String"), @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") @PostMapping(value = "/login")
@ApiException(USER_LOGIN_FAILURE)
public Result login(@RequestParam(value = "userName") String userName, public Result login(@RequestParam(value = "userName") String userName,
@RequestParam(value = "userPassword") String userPassword, @RequestParam(value = "userPassword") String userPassword,
HttpServletRequest request, HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
try {
logger.info("login user name: {} ", userName); logger.info("login user name: {} ", userName);
//user name check //user name check
@ -110,10 +110,6 @@ public class LoginController extends BaseController {
} }
return result; return result;
} catch (Exception e) {
logger.error(USER_LOGIN_FAILURE.getMsg(),e);
return error(USER_LOGIN_FAILURE.getCode(), USER_LOGIN_FAILURE.getMsg());
}
} }
/** /**
@ -125,19 +121,14 @@ public class LoginController extends BaseController {
*/ */
@ApiOperation(value = "signOut", notes = "SIGNOUT_NOTES") @ApiOperation(value = "signOut", notes = "SIGNOUT_NOTES")
@PostMapping(value = "/signOut") @PostMapping(value = "/signOut")
@ApiException(SIGN_OUT_ERROR)
public Result signOut(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result signOut(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
HttpServletRequest request) { HttpServletRequest request) {
try {
logger.info("login user:{} sign out", loginUser.getUserName()); logger.info("login user:{} sign out", loginUser.getUserName());
String ip = getClientIpAddress(request); String ip = getClientIpAddress(request);
sessionService.signOut(ip, loginUser); sessionService.signOut(ip, loginUser);
//clear session //clear session
request.removeAttribute(Constants.SESSION_USER); request.removeAttribute(Constants.SESSION_USER);
return success(); return success();
} catch (Exception e) {
logger.error(SIGN_OUT_ERROR.getMsg(),e);
return error(SIGN_OUT_ERROR.getCode(), SIGN_OUT_ERROR.getMsg());
}
} }
} }

45
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/MonitorController.java

@ -17,6 +17,7 @@
package org.apache.dolphinscheduler.api.controller; 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.service.MonitorService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
@ -33,13 +34,14 @@ import springfox.documentation.annotations.ApiIgnore;
import java.util.Map; import java.util.Map;
import static org.apache.dolphinscheduler.api.enums.Status.*; import static org.apache.dolphinscheduler.api.enums.Status.*;
/** /**
* monitor controller * monitor controller
*/ */
@Api(tags = "MONITOR_TAG", position = 1) @Api(tags = "MONITOR_TAG", position = 1)
@RestController @RestController
@RequestMapping("/monitor") @RequestMapping("/monitor")
public class MonitorController extends BaseController{ public class MonitorController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(MonitorController.class); private static final Logger logger = LoggerFactory.getLogger(MonitorController.class);
@ -48,84 +50,67 @@ public class MonitorController extends BaseController{
/** /**
* master list * master list
*
* @param loginUser login user * @param loginUser login user
* @return master list * @return master list
*/ */
@ApiOperation(value = "listMaster", notes= "MASTER_LIST_NOTES") @ApiOperation(value = "listMaster", notes = "MASTER_LIST_NOTES")
@GetMapping(value = "/master/list") @GetMapping(value = "/master/list")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(LIST_MASTERS_ERROR)
public Result listMaster(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { public Result listMaster(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
logger.info("login user: {}, query all master", loginUser.getUserName()); logger.info("login user: {}, query all master", loginUser.getUserName());
try{
logger.info("list master, user:{}", loginUser.getUserName()); logger.info("list master, user:{}", loginUser.getUserName());
Map<String, Object> result = monitorService.queryMaster(loginUser); Map<String, Object> result = monitorService.queryMaster(loginUser);
return returnDataList(result); return returnDataList(result);
}catch (Exception e){
logger.error(LIST_MASTERS_ERROR.getMsg(),e);
return error(LIST_MASTERS_ERROR.getCode(),
LIST_MASTERS_ERROR.getMsg());
}
} }
/** /**
* worker list * worker list
*
* @param loginUser login user * @param loginUser login user
* @return worker information list * @return worker information list
*/ */
@ApiOperation(value = "listWorker", notes= "WORKER_LIST_NOTES") @ApiOperation(value = "listWorker", notes = "WORKER_LIST_NOTES")
@GetMapping(value = "/worker/list") @GetMapping(value = "/worker/list")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(LIST_WORKERS_ERROR)
public Result listWorker(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { public Result listWorker(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
logger.info("login user: {}, query all workers", loginUser.getUserName()); logger.info("login user: {}, query all workers", loginUser.getUserName());
try{
Map<String, Object> result = monitorService.queryWorker(loginUser); Map<String, Object> result = monitorService.queryWorker(loginUser);
return returnDataList(result); return returnDataList(result);
}catch (Exception e){
logger.error(LIST_WORKERS_ERROR.getMsg(),e);
return error(LIST_WORKERS_ERROR.getCode(),
LIST_WORKERS_ERROR.getMsg());
}
} }
/** /**
* query database state * query database state
*
* @param loginUser login user * @param loginUser login user
* @return data base state * @return data base state
*/ */
@ApiOperation(value = "queryDatabaseState", notes= "QUERY_DATABASE_STATE_NOTES") @ApiOperation(value = "queryDatabaseState", notes = "QUERY_DATABASE_STATE_NOTES")
@GetMapping(value = "/database") @GetMapping(value = "/database")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_DATABASE_STATE_ERROR)
public Result queryDatabaseState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { public Result queryDatabaseState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
logger.info("login user: {}, query database state", loginUser.getUserName()); logger.info("login user: {}, query database state", loginUser.getUserName());
try{
Map<String, Object> result = monitorService.queryDatabaseState(loginUser); Map<String, Object> result = monitorService.queryDatabaseState(loginUser);
return returnDataList(result); 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());
}
} }
/** /**
* query zookeeper state * query zookeeper state
*
* @param loginUser login user * @param loginUser login user
* @return zookeeper information list * @return zookeeper information list
*/ */
@ApiOperation(value = "queryZookeeperState", notes= "QUERY_ZOOKEEPER_STATE_NOTES") @ApiOperation(value = "queryZookeeperState", notes = "QUERY_ZOOKEEPER_STATE_NOTES")
@GetMapping(value = "/zookeeper/list") @GetMapping(value = "/zookeeper/list")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_ZOOKEEPER_STATE_ERROR)
public Result queryZookeeperState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { public Result queryZookeeperState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
logger.info("login user: {}, query zookeeper state", loginUser.getUserName()); logger.info("login user: {}, query zookeeper state", loginUser.getUserName());
try{
Map<String, Object> result = monitorService.queryZookeeperState(loginUser); Map<String, Object> result = monitorService.queryZookeeperState(loginUser);
return returnDataList(result); 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());
}
} }
} }

220
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java

@ -16,7 +16,9 @@
*/ */
package org.apache.dolphinscheduler.api.controller; package org.apache.dolphinscheduler.api.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.dolphinscheduler.api.enums.Status; 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.ProcessDefinitionService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
@ -37,6 +39,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.apache.dolphinscheduler.api.enums.Status.*;
/** /**
* process definition controller * process definition controller
@ -44,7 +48,7 @@ import java.util.Map;
@Api(tags = "PROCESS_DEFINITION_TAG", position = 2) @Api(tags = "PROCESS_DEFINITION_TAG", position = 2)
@RestController @RestController
@RequestMapping("projects/{projectName}/process") @RequestMapping("projects/{projectName}/process")
public class ProcessDefinitionController extends BaseController{ public class ProcessDefinitionController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(ProcessDefinitionController.class); private static final Logger logger = LoggerFactory.getLogger(ProcessDefinitionController.class);
@ -63,35 +67,31 @@ public class ProcessDefinitionController extends BaseController{
* @param connects connects for nodes * @param connects connects for nodes
* @return create result code * @return create result code
*/ */
@ApiOperation(value = "save", notes= "CREATE_PROCESS_DEFINITION_NOTES") @ApiOperation(value = "save", notes = "CREATE_PROCESS_DEFINITION_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, type = "String"), @ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, type = "String"),
@ApiImplicitParam(name = "processDefinitionJson", value = "PROCESS_DEFINITION_JSON", 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 = "locations", value = "PROCESS_DEFINITION_LOCATIONS", required = true, type = "String"),
@ApiImplicitParam(name = "connects", value = "PROCESS_DEFINITION_CONNECTS", 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 = "description", value = "PROCESS_DEFINITION_DESC", required = false, type = "String"),
}) })
@PostMapping(value = "/save") @PostMapping(value = "/save")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_PROCESS_DEFINITION)
public Result createProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result createProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
@RequestParam(value = "name", required = true) String name, @RequestParam(value = "name", required = true) String name,
@RequestParam(value = "processDefinitionJson", required = true) String json, @RequestParam(value = "processDefinitionJson", required = true) String json,
@RequestParam(value = "locations", required = true) String locations, @RequestParam(value = "locations", required = true) String locations,
@RequestParam(value = "connects", required = true) String connects, @RequestParam(value = "connects", required = true) String connects,
@RequestParam(value = "description", required = false) String description) { @RequestParam(value = "description", required = false) String description) throws JsonProcessingException {
try {
logger.info("login user {}, create process definition, project name: {}, process definition name: {}, " + logger.info("login user {}, create process definition, project name: {}, process definition name: {}, " +
"process_definition_json: {}, desc: {} locations:{}, connects:{}", "process_definition_json: {}, desc: {} locations:{}, connects:{}",
loginUser.getUserName(), projectName, name, json, description, locations, connects); loginUser.getUserName(), projectName, name, json, description, locations, connects);
Map<String, Object> result = processDefinitionService.createProcessDefinition(loginUser, projectName, name, json, Map<String, Object> result = processDefinitionService.createProcessDefinition(loginUser, projectName, name, json,
description, locations, connects); description, locations, connects);
return returnDataList(result); 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());
}
} }
/** /**
@ -108,18 +108,14 @@ public class ProcessDefinitionController extends BaseController{
}) })
@GetMapping(value = "/verify-name") @GetMapping(value = "/verify-name")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR)
public Result verifyProccessDefinitionName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result verifyProccessDefinitionName(@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(value = "name", required = true) String name){ @RequestParam(value = "name", required = true) String name) {
try {
logger.info("verify process definition name unique, user:{}, project name:{}, process definition name:{}", logger.info("verify process definition name unique, user:{}, project name:{}, process definition name:{}",
loginUser.getUserName(), projectName, name); loginUser.getUserName(), projectName, name);
Map<String, Object> result = processDefinitionService.verifyProccessDefinitionName(loginUser, projectName, name); Map<String, Object> result = processDefinitionService.verifyProccessDefinitionName(loginUser, projectName, name);
return returnDataList(result); 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());
}
} }
/** /**
@ -135,19 +131,20 @@ public class ProcessDefinitionController extends BaseController{
* @param connects connects for nodes * @param connects connects for nodes
* @return update result code * @return update result code
*/ */
@ApiOperation(value = "updateProccessDefinition", notes= "UPDATE_PROCCESS_DEFINITION_NOTES") @ApiOperation(value = "updateProccessDefinition", notes = "UPDATE_PROCCESS_DEFINITION_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, type = "String"), @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 = "id", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "processDefinitionJson", value = "PROCESS_DEFINITION_JSON", 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 = "locations", value = "PROCESS_DEFINITION_LOCATIONS", required = true, type = "String"),
@ApiImplicitParam(name = "connects", value = "PROCESS_DEFINITION_CONNECTS", 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 = "description", value = "PROCESS_DEFINITION_DESC", required = false, type = "String"),
}) })
@PostMapping(value = "/update") @PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_PROCESS_DEFINITION_ERROR)
public Result updateProccessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result updateProccessDefinition(@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(value = "name", required = true) String name, @RequestParam(value = "name", required = true) String name,
@RequestParam(value = "id", required = true) int id, @RequestParam(value = "id", required = true) int id,
@RequestParam(value = "processDefinitionJson", required = true) String processDefinitionJson, @RequestParam(value = "processDefinitionJson", required = true) String processDefinitionJson,
@ -155,17 +152,12 @@ public class ProcessDefinitionController extends BaseController{
@RequestParam(value = "connects", required = false) String connects, @RequestParam(value = "connects", required = false) String connects,
@RequestParam(value = "description", required = false) String description) { @RequestParam(value = "description", required = false) String description) {
try {
logger.info("login user {}, update process define, project name: {}, process define name: {}, " + logger.info("login user {}, update process define, project name: {}, process define name: {}, " +
"process_definition_json: {}, desc: {}, locations:{}, connects:{}", "process_definition_json: {}, desc: {}, locations:{}, connects:{}",
loginUser.getUserName(), projectName, name, processDefinitionJson,description, locations, connects); loginUser.getUserName(), projectName, name, processDefinitionJson, description, locations, connects);
Map<String, Object> result = processDefinitionService.updateProcessDefinition(loginUser, projectName, id, name, Map<String, Object> result = processDefinitionService.updateProcessDefinition(loginUser, projectName, id, name,
processDefinitionJson, description, locations, connects); processDefinitionJson, description, locations, connects);
return returnDataList(result); 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());
}
} }
/** /**
@ -177,7 +169,7 @@ public class ProcessDefinitionController extends BaseController{
* @param releaseState release state * @param releaseState release state
* @return release result code * @return release result code
*/ */
@ApiOperation(value = "releaseProccessDefinition", notes= "RELEASE_PROCCESS_DEFINITION_NOTES") @ApiOperation(value = "releaseProccessDefinition", notes = "RELEASE_PROCCESS_DEFINITION_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, type = "String"), @ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, type = "String"),
@ApiImplicitParam(name = "processId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "processId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"),
@ -185,20 +177,16 @@ public class ProcessDefinitionController extends BaseController{
}) })
@PostMapping(value = "/release") @PostMapping(value = "/release")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(RELEASE_PROCESS_DEFINITION_ERROR)
public Result releaseProccessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result releaseProccessDefinition(@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(value = "processId", required = true) int processId, @RequestParam(value = "processId", required = true) int processId,
@RequestParam(value = "releaseState", required = true) int releaseState) { @RequestParam(value = "releaseState", required = true) int releaseState) {
try {
logger.info("login user {}, release process definition, project name: {}, release state: {}", logger.info("login user {}, release process definition, project name: {}, release state: {}",
loginUser.getUserName(), projectName, releaseState); loginUser.getUserName(), projectName, releaseState);
Map<String, Object> result = processDefinitionService.releaseProcessDefinition(loginUser, projectName, processId, releaseState); Map<String, Object> result = processDefinitionService.releaseProcessDefinition(loginUser, projectName, processId, releaseState);
return returnDataList(result); 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());
}
} }
@ -210,25 +198,21 @@ public class ProcessDefinitionController extends BaseController{
* @param processId process definition id * @param processId process definition id
* @return process definition detail * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "processId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100") @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) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR)
public Result queryProccessDefinitionById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, 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 @RequestParam("processId") Integer processId
){ ) {
try{
logger.info("query datail of process definition, login user:{}, project name:{}, process definition id:{}", logger.info("query datail of process definition, login user:{}, project name:{}, process definition id:{}",
loginUser.getUserName(), projectName, processId); loginUser.getUserName(), projectName, processId);
Map<String, Object> result = processDefinitionService.queryProccessDefinitionById(loginUser, projectName, processId); Map<String, Object> result = processDefinitionService.queryProccessDefinitionById(loginUser, projectName, processId);
return returnDataList(result); 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());
}
} }
@ -239,25 +223,22 @@ public class ProcessDefinitionController extends BaseController{
* @param projectName project name * @param projectName project name
* @return process definition list * @return process definition list
*/ */
@ApiOperation(value = "queryProccessDefinitionList", notes= "QUERY_PROCCESS_DEFINITION_LIST_NOTES") @ApiOperation(value = "queryProccessDefinitionList", notes = "QUERY_PROCCESS_DEFINITION_LIST_NOTES")
@GetMapping(value="/list") @GetMapping(value = "/list")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_PROCCESS_DEFINITION_LIST)
public Result queryProccessDefinitionList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryProccessDefinitionList(@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
){ ) {
try{
logger.info("query proccess definition list, login user:{}, project name:{}", logger.info("query proccess definition list, login user:{}, project name:{}",
loginUser.getUserName(), projectName); loginUser.getUserName(), projectName);
Map<String, Object> result = processDefinitionService.queryProccessDefinitionList(loginUser, projectName); Map<String, Object> result = processDefinitionService.queryProccessDefinitionList(loginUser, projectName);
return returnDataList(result); 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());
}
} }
/** /**
* query proccess definition list paging * query proccess definition list paging
*
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectName project name
* @param searchVal search value * @param searchVal search value
@ -266,34 +247,30 @@ public class ProcessDefinitionController extends BaseController{
* @param userId user id * @param userId user id
* @return process definition page * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", required = false, type = "String"), @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", required = false, type = "String"),
@ApiImplicitParam(name = "userId", value = "USER_ID", required = false, dataType = "Int", example = "100"), @ApiImplicitParam(name = "userId", value = "USER_ID", required = false, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, 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) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_PROCCESS_DEFINITION_LIST_PAGING_ERROR)
public Result queryProcessDefinitionListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, 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("pageNo") Integer pageNo,
@RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam(value = "userId", required = false, defaultValue = "0") Integer userId, @RequestParam(value = "userId", required = false, defaultValue = "0") Integer userId,
@RequestParam("pageSize") Integer pageSize){ @RequestParam("pageSize") Integer pageSize) {
try{
logger.info("query proccess definition list paging, login user:{}, project name:{}", loginUser.getUserName(), projectName); logger.info("query proccess definition list paging, login user:{}, project name:{}", loginUser.getUserName(), projectName);
Map<String, Object> result = checkPageParams(pageNo, pageSize); Map<String, Object> result = checkPageParams(pageNo, pageSize);
if(result.get(Constants.STATUS) != Status.SUCCESS){ if (result.get(Constants.STATUS) != Status.SUCCESS) {
return returnDataListPaging(result); return returnDataListPaging(result);
} }
searchVal = ParameterUtils.handleEscapes(searchVal); searchVal = ParameterUtils.handleEscapes(searchVal);
result = processDefinitionService.queryProcessDefinitionListPaging(loginUser, projectName, searchVal, pageNo, pageSize, userId); result = processDefinitionService.queryProcessDefinitionListPaging(loginUser, projectName, searchVal, pageNo, pageSize, userId);
return returnDataListPaging(result); 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());
}
} }
@ -306,88 +283,72 @@ public class ProcessDefinitionController extends BaseController{
* @param limit limit * @param limit limit
* @return tree view json data * @return tree view json data
*/ */
@ApiOperation(value = "viewTree", notes= "VIEW_TREE_NOTES") @ApiOperation(value = "viewTree", notes = "VIEW_TREE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "processId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "limit", value = "LIMIT", required = true, dataType = "Int", example = "100") @ApiImplicitParam(name = "limit", value = "LIMIT", required = true, dataType = "Int", example = "100")
}) })
@GetMapping(value="/view-tree") @GetMapping(value = "/view-tree")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(ENCAPSULATION_TREEVIEW_STRUCTURE_ERROR)
public Result viewTree(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result viewTree(@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 id, @RequestParam("processId") Integer id,
@RequestParam("limit") Integer limit){ @RequestParam("limit") Integer limit) throws Exception {
try{
Map<String, Object> result = processDefinitionService.viewTree(id, limit); Map<String, Object> result = processDefinitionService.viewTree(id, limit);
return returnDataList(result); 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());
}
} }
/** /**
*
* get tasks list by process definition id * get tasks list by process definition id
* *
*
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectName project name
* @param processDefinitionId process definition id * @param processDefinitionId process definition id
* @return task list * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100") @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100")
}) })
@GetMapping(value="gen-task-list") @GetMapping(value = "gen-task-list")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR)
public Result getNodeListByDefinitionId( public Result getNodeListByDefinitionId(
@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @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("processDefinitionId") Integer processDefinitionId){ @RequestParam("processDefinitionId") Integer processDefinitionId) throws Exception {
try {
logger.info("query task node name list by definitionId, login user:{}, project name:{}, id : {}", logger.info("query task node name list by definitionId, login user:{}, project name:{}, id : {}",
loginUser.getUserName(), projectName, processDefinitionId); loginUser.getUserName(), projectName, processDefinitionId);
Map<String, Object> result = processDefinitionService.getTaskNodeListByDefinitionId(processDefinitionId); Map<String, Object> result = processDefinitionService.getTaskNodeListByDefinitionId(processDefinitionId);
return returnDataList(result); 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());
}
} }
/** /**
*
* get tasks list by process definition id * get tasks list by process definition id
* *
*
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectName project name
* @param processDefinitionIdList process definition id list * @param processDefinitionIdList process definition id list
* @return node list data * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionIdList", value = "PROCESS_DEFINITION_ID_LIST", required = true, type = "String") @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) @ResponseStatus(HttpStatus.OK)
@ApiException(GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR)
public Result getNodeListByDefinitionIdList( public Result getNodeListByDefinitionIdList(
@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @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("processDefinitionIdList") String processDefinitionIdList){ @RequestParam("processDefinitionIdList") String processDefinitionIdList) throws Exception {
try {
logger.info("query task node name list by definitionId list, login user:{}, project name:{}, id list: {}", logger.info("query task node name list by definitionId list, login user:{}, project name:{}, id list: {}",
loginUser.getUserName(), projectName, processDefinitionIdList); loginUser.getUserName(), projectName, processDefinitionIdList);
Map<String, Object> result = processDefinitionService.getTaskNodeListByDefinitionIdList(processDefinitionIdList); Map<String, Object> result = processDefinitionService.getTaskNodeListByDefinitionIdList(processDefinitionIdList);
return returnDataList(result); 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());
}
} }
/** /**
@ -398,25 +359,21 @@ public class ProcessDefinitionController extends BaseController{
* @param processDefinitionId process definition id * @param processDefinitionId process definition id
* @return delete result code * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", dataType = "Int", example = "100") @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", dataType = "Int", example = "100")
}) })
@GetMapping(value="/delete") @GetMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_PROCESS_DEFINE_BY_ID_ERROR)
public Result deleteProcessDefinitionById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result deleteProcessDefinitionById(@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("processDefinitionId") Integer processDefinitionId @RequestParam("processDefinitionId") Integer processDefinitionId
){ ) {
try{
logger.info("delete process definition by id, login user:{}, project name:{}, process definition id:{}", logger.info("delete process definition by id, login user:{}, project name:{}, process definition id:{}",
loginUser.getUserName(), projectName, processDefinitionId); loginUser.getUserName(), projectName, processDefinitionId);
Map<String, Object> result = processDefinitionService.deleteProcessDefinitionById(loginUser, projectName, processDefinitionId); Map<String, Object> result = processDefinitionService.deleteProcessDefinitionById(loginUser, projectName, processDefinitionId);
return returnDataList(result); 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());
}
} }
/** /**
@ -427,32 +384,32 @@ public class ProcessDefinitionController extends BaseController{
* @param processDefinitionIds process definition id list * @param processDefinitionIds process definition id list
* @return delete result code * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionIds", value = "PROCESS_DEFINITION_IDS", type = "String") @ApiImplicitParam(name = "processDefinitionIds", value = "PROCESS_DEFINITION_IDS", type = "String")
}) })
@GetMapping(value="/batch-delete") @GetMapping(value = "/batch-delete")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR)
public Result batchDeleteProcessDefinitionByIds(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result batchDeleteProcessDefinitionByIds(@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("processDefinitionIds") String processDefinitionIds @RequestParam("processDefinitionIds") String processDefinitionIds
){ ) {
try{
logger.info("delete process definition by ids, login user:{}, project name:{}, process definition ids:{}", logger.info("delete process definition by ids, login user:{}, project name:{}, process definition ids:{}",
loginUser.getUserName(), projectName, processDefinitionIds); loginUser.getUserName(), projectName, processDefinitionIds);
Map<String, Object> result = new HashMap<>(5); Map<String, Object> result = new HashMap<>(5);
List<String> deleteFailedIdList = new ArrayList<>(); List<String> deleteFailedIdList = new ArrayList<>();
if(StringUtils.isNotEmpty(processDefinitionIds)){ if (StringUtils.isNotEmpty(processDefinitionIds)) {
String[] processDefinitionIdArray = processDefinitionIds.split(","); String[] processDefinitionIdArray = processDefinitionIds.split(",");
for (String strProcessDefinitionId:processDefinitionIdArray) { for (String strProcessDefinitionId : processDefinitionIdArray) {
int processDefinitionId = Integer.parseInt(strProcessDefinitionId); int processDefinitionId = Integer.parseInt(strProcessDefinitionId);
try { try {
Map<String, Object> deleteResult = processDefinitionService.deleteProcessDefinitionById(loginUser, projectName, processDefinitionId); Map<String, Object> deleteResult = processDefinitionService.deleteProcessDefinitionById(loginUser, projectName, processDefinitionId);
if(!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))){ if (!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))) {
deleteFailedIdList.add(strProcessDefinitionId); deleteFailedIdList.add(strProcessDefinitionId);
logger.error((String)deleteResult.get(Constants.MSG)); logger.error((String) deleteResult.get(Constants.MSG));
} }
} catch (Exception e) { } catch (Exception e) {
deleteFailedIdList.add(strProcessDefinitionId); deleteFailedIdList.add(strProcessDefinitionId);
@ -460,17 +417,13 @@ public class ProcessDefinitionController extends BaseController{
} }
} }
if(!deleteFailedIdList.isEmpty()){ if (!deleteFailedIdList.isEmpty()) {
putMsg(result, Status.BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR, String.join(",", deleteFailedIdList)); putMsg(result, Status.BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR, String.join(",", deleteFailedIdList));
}else{ } else {
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
} }
return returnDataList(result); 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());
}
} }
/** /**
@ -481,27 +434,26 @@ public class ProcessDefinitionController extends BaseController{
* @param processDefinitionId process definition id * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100") @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100")
}) })
@GetMapping(value="/export") @GetMapping(value = "/export")
@ResponseBody @ResponseBody
public void exportProcessDefinitionById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public void exportProcessDefinitionById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName, @PathVariable String projectName,
@RequestParam("processDefinitionId") Integer processDefinitionId, @RequestParam("processDefinitionId") Integer processDefinitionId,
HttpServletResponse response){ HttpServletResponse response) {
try{ try {
logger.info("export process definition by id, login user:{}, project name:{}, process definition id:{}", logger.info("export process definition by id, login user:{}, project name:{}, process definition id:{}",
loginUser.getUserName(), projectName, processDefinitionId); loginUser.getUserName(), projectName, processDefinitionId);
processDefinitionService.exportProcessDefinitionById(loginUser, projectName, processDefinitionId,response); processDefinitionService.exportProcessDefinitionById(loginUser, projectName, processDefinitionId, response);
}catch (Exception e){ } catch (Exception e) {
logger.error(Status.EXPORT_PROCESS_DEFINE_BY_ID_ERROR.getMsg(),e); logger.error(Status.EXPORT_PROCESS_DEFINE_BY_ID_ERROR.getMsg(), e);
} }
} }
/** /**
* query proccess definition all by project id * query proccess definition all by project id
* *
@ -509,20 +461,16 @@ public class ProcessDefinitionController extends BaseController{
* @param projectId project id * @param projectId project id
* @return process definition list * @return process definition list
*/ */
@ApiOperation(value = "queryProccessDefinitionAllByProjectId", notes= "QUERY_PROCCESS_DEFINITION_All_BY_PROJECT_ID_NOTES") @ApiOperation(value = "queryProccessDefinitionAllByProjectId", notes = "QUERY_PROCCESS_DEFINITION_All_BY_PROJECT_ID_NOTES")
@GetMapping(value="/queryProccessDefinitionAllByProjectId") @GetMapping(value = "/queryProccessDefinitionAllByProjectId")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_PROCCESS_DEFINITION_LIST)
public Result queryProccessDefinitionAllByProjectId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryProccessDefinitionAllByProjectId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("projectId") Integer projectId){ @RequestParam("projectId") Integer projectId) {
try{
logger.info("query proccess definition list, login user:{}, project id:{}", logger.info("query proccess definition list, login user:{}, project id:{}",
loginUser.getUserName(),projectId); loginUser.getUserName(), projectId);
Map<String, Object> result = processDefinitionService.queryProccessDefinitionAllByProjectId(projectId); Map<String, Object> result = processDefinitionService.queryProccessDefinitionAllByProjectId(projectId);
return returnDataList(result); 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());
}
} }
} }

161
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java

@ -17,6 +17,7 @@
package org.apache.dolphinscheduler.api.controller; package org.apache.dolphinscheduler.api.controller;
import org.apache.dolphinscheduler.api.enums.Status; 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.service.ProcessInstanceService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
@ -33,6 +34,8 @@ import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -46,7 +49,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.*;
@Api(tags = "PROCESS_INSTANCE_TAG", position = 10) @Api(tags = "PROCESS_INSTANCE_TAG", position = 10)
@RestController @RestController
@RequestMapping("projects/{projectName}/instance") @RequestMapping("projects/{projectName}/instance")
public class ProcessInstanceController extends BaseController{ public class ProcessInstanceController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(ProcessInstanceController.class); private static final Logger logger = LoggerFactory.getLogger(ProcessInstanceController.class);
@ -69,20 +72,21 @@ public class ProcessInstanceController extends BaseController{
* @param endTime end time * @param endTime end time
* @return process instance list * @return process instance list
*/ */
@ApiOperation(value = "queryProcessInstanceList", notes= "QUERY_PROCESS_INSTANCE_LIST_NOTES") @ApiOperation(value = "queryProcessInstanceList", notes = "QUERY_PROCESS_INSTANCE_LIST_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", dataType = "Int", example = "100"), @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type ="String"), @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"),
@ApiImplicitParam(name = "executorName", value = "EXECUTOR_NAME", type ="String"), @ApiImplicitParam(name = "executorName", value = "EXECUTOR_NAME", type = "String"),
@ApiImplicitParam(name = "stateType", value = "EXECUTION_STATUS", type ="ExecutionStatus"), @ApiImplicitParam(name = "stateType", value = "EXECUTION_STATUS", type = "ExecutionStatus"),
@ApiImplicitParam(name = "host", value = "HOST", type ="String"), @ApiImplicitParam(name = "host", value = "HOST", type = "String"),
@ApiImplicitParam(name = "startDate", value = "START_DATE", type ="String"), @ApiImplicitParam(name = "startDate", value = "START_DATE", type = "String"),
@ApiImplicitParam(name = "endDate", value = "END_DATE", type ="String"), @ApiImplicitParam(name = "endDate", value = "END_DATE", type = "String"),
@ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "100"), @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", 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) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR)
public Result queryProcessInstanceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryProcessInstanceList(@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(value = "processDefinitionId", required = false, defaultValue = "0") Integer processDefinitionId, @RequestParam(value = "processDefinitionId", required = false, defaultValue = "0") Integer processDefinitionId,
@ -93,20 +97,15 @@ public class ProcessInstanceController extends BaseController{
@RequestParam(value = "startDate", required = false) String startTime, @RequestParam(value = "startDate", required = false) String startTime,
@RequestParam(value = "endDate", required = false) String endTime, @RequestParam(value = "endDate", required = false) String endTime,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize){ @RequestParam("pageSize") Integer pageSize) {
try{
logger.info("query all process instance list, login user:{},project name:{}, define id:{}," + 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:{}", "search value:{},executor name:{},state type:{},host:{},start time:{}, end time:{},page number:{}, page size:{}",
loginUser.getUserName(), projectName, processDefinitionId, searchVal, executorName,stateType,host, loginUser.getUserName(), projectName, processDefinitionId, searchVal, executorName, stateType, host,
startTime, endTime, pageNo, pageSize); startTime, endTime, pageNo, pageSize);
searchVal = ParameterUtils.handleEscapes(searchVal); searchVal = ParameterUtils.handleEscapes(searchVal);
Map<String, Object> result = processInstanceService.queryProcessInstanceList( Map<String, Object> result = processInstanceService.queryProcessInstanceList(
loginUser, projectName, processDefinitionId, startTime, endTime, searchVal, executorName, stateType, host, pageNo, pageSize); loginUser, projectName, processDefinitionId, startTime, endTime, searchVal, executorName, stateType, host, pageNo, pageSize);
return returnDataListPaging(result); 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());
}
} }
/** /**
@ -117,25 +116,21 @@ public class ProcessInstanceController extends BaseController{
* @param processInstanceId process instance id * @param processInstanceId process instance id
* @return task list for the process instance * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", dataType = "Int", example = "100") @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) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_ERROR)
public Result queryTaskListByProcessId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryTaskListByProcessId(@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("processInstanceId") Integer processInstanceId @RequestParam("processInstanceId") Integer processInstanceId
) { ) throws IOException {
try{
logger.info("query task instance list by process instance id, login user:{}, project name:{}, process instance id:{}", logger.info("query task instance list by process instance id, login user:{}, project name:{}, process instance id:{}",
loginUser.getUserName(), projectName, processInstanceId); loginUser.getUserName(), projectName, processInstanceId);
Map<String, Object> result = processInstanceService.queryTaskListByProcessId(loginUser, projectName, processInstanceId); Map<String, Object> result = processInstanceService.queryTaskListByProcessId(loginUser, projectName, processInstanceId);
return returnDataList(result); 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());
}
} }
/** /**
@ -152,7 +147,7 @@ public class ProcessInstanceController extends BaseController{
* @param connects connects * @param connects connects
* @return update result code * @return update result code
*/ */
@ApiOperation(value = "updateProcessInstance", notes= "UPDATE_PROCESS_INSTANCE_NOTES") @ApiOperation(value = "updateProcessInstance", notes = "UPDATE_PROCESS_INSTANCE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processInstanceJson", value = "PROCESS_INSTANCE_JSON", type = "String"), @ApiImplicitParam(name = "processInstanceJson", value = "PROCESS_INSTANCE_JSON", type = "String"),
@ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", dataType = "Int", example = "100"), @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", dataType = "Int", example = "100"),
@ -162,19 +157,19 @@ public class ProcessInstanceController extends BaseController{
@ApiImplicitParam(name = "connects", value = "PROCESS_INSTANCE_CONNECTS", type = "String"), @ApiImplicitParam(name = "connects", value = "PROCESS_INSTANCE_CONNECTS", type = "String"),
@ApiImplicitParam(name = "flag", value = "RECOVERY_PROCESS_INSTANCE_FLAG", type = "Flag"), @ApiImplicitParam(name = "flag", value = "RECOVERY_PROCESS_INSTANCE_FLAG", type = "Flag"),
}) })
@PostMapping(value="/update") @PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_PROCESS_INSTANCE_ERROR)
public Result updateProcessInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result updateProcessInstance(@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( value = "processInstanceJson", required = false) String processInstanceJson, @RequestParam(value = "processInstanceJson", required = false) String processInstanceJson,
@RequestParam( value = "processInstanceId") Integer processInstanceId, @RequestParam(value = "processInstanceId") Integer processInstanceId,
@RequestParam( value = "scheduleTime", required = false) String scheduleTime, @RequestParam(value = "scheduleTime", required = false) String scheduleTime,
@RequestParam( value = "syncDefine", required = true) Boolean syncDefine, @RequestParam(value = "syncDefine", required = true) Boolean syncDefine,
@RequestParam(value = "locations", required = false) String locations, @RequestParam(value = "locations", required = false) String locations,
@RequestParam(value = "connects", required = false) String connects, @RequestParam(value = "connects", required = false) String connects,
@RequestParam( value = "flag", required = false) Flag flag @RequestParam(value = "flag", required = false) Flag flag
){ ) throws ParseException {
try{
logger.info("updateProcessInstance process instance, login user:{}, project name:{}, process instance json:{}," + logger.info("updateProcessInstance process instance, login user:{}, project name:{}, process instance json:{}," +
"process instance id:{}, schedule time:{}, sync define:{}, flag:{}, locations:{}, connects:{}", "process instance id:{}, schedule time:{}, sync define:{}, flag:{}, locations:{}, connects:{}",
loginUser.getUserName(), projectName, processInstanceJson, processInstanceId, scheduleTime, loginUser.getUserName(), projectName, processInstanceJson, processInstanceId, scheduleTime,
@ -182,10 +177,6 @@ public class ProcessInstanceController extends BaseController{
Map<String, Object> result = processInstanceService.updateProcessInstance(loginUser, projectName, Map<String, Object> result = processInstanceService.updateProcessInstance(loginUser, projectName,
processInstanceId, processInstanceJson, scheduleTime, syncDefine, flag, locations, connects); processInstanceId, processInstanceJson, scheduleTime, syncDefine, flag, locations, connects);
return returnDataList(result); 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());
}
} }
/** /**
@ -196,25 +187,21 @@ public class ProcessInstanceController extends BaseController{
* @param processInstanceId process instance id * @param processInstanceId process instance id
* @return process instance detail * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", dataType = "Int", example = "100") @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", dataType = "Int", example = "100")
}) })
@GetMapping(value="/select-by-id") @GetMapping(value = "/select-by-id")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_PROCESS_INSTANCE_BY_ID_ERROR)
public Result queryProcessInstanceById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryProcessInstanceById(@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("processInstanceId") Integer processInstanceId @RequestParam("processInstanceId") Integer processInstanceId
){ ) {
try{
logger.info("query process instance detail by id, login user:{},project name:{}, process instance id:{}", logger.info("query process instance detail by id, login user:{},project name:{}, process instance id:{}",
loginUser.getUserName(), projectName, processInstanceId); loginUser.getUserName(), projectName, processInstanceId);
Map<String, Object> result = processInstanceService.queryProcessInstanceById(loginUser, projectName, processInstanceId); Map<String, Object> result = processInstanceService.queryProcessInstanceById(loginUser, projectName, processInstanceId);
return returnDataList(result); 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());
}
} }
/** /**
@ -226,26 +213,22 @@ public class ProcessInstanceController extends BaseController{
* @param processInstanceId process instance id * @param processInstanceId process instance id
* @return delete result code * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", dataType = "Int", example = "100") @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", dataType = "Int", example = "100")
}) })
@GetMapping(value="/delete") @GetMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_PROCESS_INSTANCE_BY_ID_ERROR)
public Result deleteProcessInstanceById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result deleteProcessInstanceById(@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("processInstanceId") Integer processInstanceId @RequestParam("processInstanceId") Integer processInstanceId
){ ) {
try{
logger.info("delete process instance by id, login user:{}, project name:{}, process instance id:{}", logger.info("delete process instance by id, login user:{}, project name:{}, process instance id:{}",
loginUser.getUserName(), projectName, processInstanceId); loginUser.getUserName(), projectName, processInstanceId);
// task queue // task queue
Map<String, Object> result = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId); Map<String, Object> result = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId);
return returnDataList(result); 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());
}
} }
/** /**
@ -256,22 +239,18 @@ public class ProcessInstanceController extends BaseController{
* @param taskId task id * @param taskId task id
* @return sub process instance detail * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "taskId", value = "TASK_ID", dataType = "Int", example = "100") @ApiImplicitParam(name = "taskId", value = "TASK_ID", dataType = "Int", example = "100")
}) })
@GetMapping(value="/select-sub-process") @GetMapping(value = "/select-sub-process")
@ResponseStatus(HttpStatus.OK) @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, public Result querySubProcessInstanceByTaskId(@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("taskId") Integer taskId){ @RequestParam("taskId") Integer taskId) {
try{
Map<String, Object> result = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, taskId); Map<String, Object> result = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, taskId);
return returnDataList(result); 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());
}
} }
/** /**
@ -282,22 +261,18 @@ public class ProcessInstanceController extends BaseController{
* @param subId sub process id * @param subId sub process id
* @return parent instance detail * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "subId", value = "SUB_PROCESS_INSTANCE_ID", dataType = "Int", example = "100") @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) @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, public Result queryParentInstanceBySubId(@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("subId") Integer subId){ @RequestParam("subId") Integer subId) {
try{
Map<String, Object> result = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, subId); Map<String, Object> result = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, subId);
return returnDataList(result); 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());
}
} }
/** /**
@ -307,21 +282,17 @@ public class ProcessInstanceController extends BaseController{
* @param processInstanceId process instance id * @param processInstanceId process instance id
* @return variables data * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", dataType = "Int", example = "100") @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", dataType = "Int", example = "100")
}) })
@GetMapping(value="/view-variables") @GetMapping(value = "/view-variables")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
public Result viewVariables(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser @ApiException(QUERY_PROCESS_INSTANCE_ALL_VARIABLES_ERROR)
, @RequestParam("processInstanceId") Integer processInstanceId){ public Result viewVariables(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
try{ @RequestParam("processInstanceId") Integer processInstanceId) throws Exception {
Map<String, Object> result = processInstanceService.viewVariables(processInstanceId); Map<String, Object> result = processInstanceService.viewVariables(processInstanceId);
return returnDataList(result); 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());
}
} }
/** /**
@ -332,22 +303,18 @@ public class ProcessInstanceController extends BaseController{
* @param processInstanceId process instance id * @param processInstanceId process instance id
* @return gantt tree data * @return gantt tree data
*/ */
@ApiOperation(value = "vieGanttTree", notes= "VIEW_GANTT_NOTES") @ApiOperation(value = "vieGanttTree", notes = "VIEW_GANTT_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", dataType = "Int", example = "100") @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", dataType = "Int", example = "100")
}) })
@GetMapping(value="/view-gantt") @GetMapping(value = "/view-gantt")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(ENCAPSULATION_PROCESS_INSTANCE_GANTT_STRUCTURE_ERROR)
public Result viewTree(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result viewTree(@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("processInstanceId") Integer processInstanceId){ @RequestParam("processInstanceId") Integer processInstanceId) throws Exception {
try{
Map<String, Object> result = processInstanceService.viewGantt(processInstanceId); Map<String, Object> result = processInstanceService.viewGantt(processInstanceId);
return returnDataList(result); 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());
}
} }
/** /**
@ -359,44 +326,40 @@ public class ProcessInstanceController extends BaseController{
* @param processInstanceIds process instance id * @param processInstanceIds process instance id
* @return delete result code * @return delete result code
*/ */
@GetMapping(value="/batch-delete") @GetMapping(value = "/batch-delete")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR)
public Result batchDeleteProcessInstanceByIds(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result batchDeleteProcessInstanceByIds(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName, @PathVariable String projectName,
@RequestParam("processInstanceIds") String processInstanceIds @RequestParam("processInstanceIds") String processInstanceIds
){ ) {
try{
logger.info("delete process instance by ids, login user:{}, project name:{}, process instance ids :{}", logger.info("delete process instance by ids, login user:{}, project name:{}, process instance ids :{}",
loginUser.getUserName(), projectName, processInstanceIds); loginUser.getUserName(), projectName, processInstanceIds);
// task queue // task queue
Map<String, Object> result = new HashMap<>(5); Map<String, Object> result = new HashMap<>(5);
List<String> deleteFailedIdList = new ArrayList<>(); List<String> deleteFailedIdList = new ArrayList<>();
if(StringUtils.isNotEmpty(processInstanceIds)){ if (StringUtils.isNotEmpty(processInstanceIds)) {
String[] processInstanceIdArray = processInstanceIds.split(","); String[] processInstanceIdArray = processInstanceIds.split(",");
for (String strProcessInstanceId:processInstanceIdArray) { for (String strProcessInstanceId : processInstanceIdArray) {
int processInstanceId = Integer.parseInt(strProcessInstanceId); int processInstanceId = Integer.parseInt(strProcessInstanceId);
try { try {
Map<String, Object> deleteResult = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId); Map<String, Object> deleteResult = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId);
if(!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))){ if (!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))) {
deleteFailedIdList.add(strProcessInstanceId); deleteFailedIdList.add(strProcessInstanceId);
logger.error((String)deleteResult.get(Constants.MSG)); logger.error((String) deleteResult.get(Constants.MSG));
} }
} catch (Exception e) { } catch (Exception e) {
deleteFailedIdList.add(strProcessInstanceId); deleteFailedIdList.add(strProcessInstanceId);
} }
} }
} }
if(!deleteFailedIdList.isEmpty()){ if (!deleteFailedIdList.isEmpty()) {
putMsg(result, Status.BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR, String.join(",", deleteFailedIdList)); putMsg(result, Status.BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR, String.join(",", deleteFailedIdList));
}else{ } else {
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
} }
return returnDataList(result); 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());
}
} }
} }

102
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java

@ -17,7 +17,7 @@
package org.apache.dolphinscheduler.api.controller; 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.ProcessDefinitionService;
import org.apache.dolphinscheduler.api.service.ProjectService; import org.apache.dolphinscheduler.api.service.ProjectService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
@ -64,25 +64,21 @@ public class ProjectController extends BaseController {
* @param description description * @param description description
* @return returns an error if it exists * @return returns an error if it exists
*/ */
@ApiOperation(value = "createProject", notes= "CREATE_PROJECT_NOTES") @ApiOperation(value = "createProject", notes = "CREATE_PROJECT_NOTES")
@ApiImplicitParams({ @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") @ApiImplicitParam(name = "description", value = "PROJECT_DESC", dataType = "String")
}) })
@PostMapping(value = "/create") @PostMapping(value = "/create")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_PROJECT_ERROR)
public Result createProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result createProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("projectName") String projectName, @RequestParam("projectName") String projectName,
@RequestParam(value = "description", required = false) String description) { @RequestParam(value = "description", required = false) String description) {
try {
logger.info("login user {}, create project name: {}, desc: {}", loginUser.getUserName(), projectName, description); logger.info("login user {}, create project name: {}, desc: {}", loginUser.getUserName(), projectName, description);
Map<String, Object> result = projectService.createProject(loginUser, projectName, description); Map<String, Object> result = projectService.createProject(loginUser, projectName, description);
return returnDataList(result); return returnDataList(result);
} catch (Exception e) {
logger.error(CREATE_PROJECT_ERROR.getMsg(), e);
return error(CREATE_PROJECT_ERROR.getCode(), CREATE_PROJECT_ERROR.getMsg());
}
} }
/** /**
@ -94,26 +90,22 @@ public class ProjectController extends BaseController {
* @param description description * @param description description
* @return update result code * @return update result code
*/ */
@ApiOperation(value = "updateProject", notes= "UPDATE_PROJECT_NOTES") @ApiOperation(value = "updateProject", notes = "UPDATE_PROJECT_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType ="Int", example = "100"), @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "projectName",value = "PROJECT_NAME",dataType = "String"), @ApiImplicitParam(name = "projectName", value = "PROJECT_NAME", dataType = "String"),
@ApiImplicitParam(name = "description", value = "PROJECT_DESC", dataType = "String") @ApiImplicitParam(name = "description", value = "PROJECT_DESC", dataType = "String")
}) })
@PostMapping(value = "/update") @PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_PROJECT_ERROR)
public Result updateProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result updateProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("projectId") Integer projectId, @RequestParam("projectId") Integer projectId,
@RequestParam("projectName") String projectName, @RequestParam("projectName") String projectName,
@RequestParam(value = "description", required = false) String description) { @RequestParam(value = "description", required = false) String description) {
try {
logger.info("login user {} , updateProcessInstance project name: {}, desc: {}", loginUser.getUserName(), projectName, description); logger.info("login user {} , updateProcessInstance project name: {}, desc: {}", loginUser.getUserName(), projectName, description);
Map<String, Object> result = projectService.update(loginUser, projectId, projectName, description); Map<String, Object> result = projectService.update(loginUser, projectId, projectName, description);
return returnDataList(result); return returnDataList(result);
} catch (Exception e) {
logger.error(UPDATE_PROJECT_ERROR.getMsg(), e);
return error(UPDATE_PROJECT_ERROR.getCode(), UPDATE_PROJECT_ERROR.getMsg());
}
} }
/** /**
@ -123,23 +115,19 @@ public class ProjectController extends BaseController {
* @param projectId project id * @param projectId project id
* @return project detail information * @return project detail information
*/ */
@ApiOperation(value = "queryProjectById", notes= "QUERY_PROJECT_BY_ID_NOTES") @ApiOperation(value = "queryProjectById", notes = "QUERY_PROJECT_BY_ID_NOTES")
@ApiImplicitParams({ @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") @GetMapping(value = "/query-by-id")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_PROJECT_DETAILS_BY_ID_ERROR)
public Result queryProjectById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryProjectById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("projectId") Integer projectId) { @RequestParam("projectId") Integer projectId) {
logger.info("login user {}, query project by id: {}", loginUser.getUserName(), projectId); logger.info("login user {}, query project by id: {}", loginUser.getUserName(), projectId);
try {
Map<String, Object> result = projectService.queryById(projectId); Map<String, Object> result = projectService.queryById(projectId);
return returnDataList(result); 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());
}
} }
/** /**
@ -151,29 +139,25 @@ public class ProjectController extends BaseController {
* @param pageNo page number * @param pageNo page number
* @return project list which the login user have permission to see * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType ="String"), @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"),
@ApiImplicitParam(name = "projectId", value = "PAGE_SIZE", dataType ="Int", example = "20"), @ApiImplicitParam(name = "projectId", value = "PAGE_SIZE", dataType = "Int", example = "20"),
@ApiImplicitParam(name = "projectId", value = "PAGE_NO", dataType ="Int", example = "1") @ApiImplicitParam(name = "projectId", value = "PAGE_NO", dataType = "Int", example = "1")
}) })
@GetMapping(value = "/list-paging") @GetMapping(value = "/list-paging")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR)
public Result queryProjectListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryProjectListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageSize") Integer pageSize, @RequestParam("pageSize") Integer pageSize,
@RequestParam("pageNo") Integer pageNo @RequestParam("pageNo") Integer pageNo
) { ) {
try {
logger.info("login user {}, query project list paging", loginUser.getUserName()); logger.info("login user {}, query project list paging", loginUser.getUserName());
searchVal = ParameterUtils.handleEscapes(searchVal); searchVal = ParameterUtils.handleEscapes(searchVal);
Map<String, Object> result = projectService.queryProjectListPaging(loginUser, pageSize, pageNo, searchVal); Map<String, Object> result = projectService.queryProjectListPaging(loginUser, pageSize, pageNo, searchVal);
return returnDataListPaging(result); 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());
}
} }
/** /**
@ -183,24 +167,20 @@ public class ProjectController extends BaseController {
* @param projectId project id * @param projectId project id
* @return delete result code * @return delete result code
*/ */
@ApiOperation(value = "deleteProjectById", notes= "DELETE_PROJECT_BY_ID_NOTES") @ApiOperation(value = "deleteProjectById", notes = "DELETE_PROJECT_BY_ID_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType ="Int", example = "100") @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100")
}) })
@GetMapping(value = "/delete") @GetMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_PROJECT_ERROR)
public Result deleteProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result deleteProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("projectId") Integer projectId @RequestParam("projectId") Integer projectId
) { ) {
try {
logger.info("login user {}, delete project: {}.", loginUser.getUserName(), projectId); logger.info("login user {}, delete project: {}.", loginUser.getUserName(), projectId);
Map<String, Object> result = projectService.deleteProject(loginUser, projectId); Map<String, Object> result = projectService.deleteProject(loginUser, projectId);
return returnDataList(result); return returnDataList(result);
} catch (Exception e) {
logger.error(DELETE_PROJECT_ERROR.getMsg(), e);
return error(DELETE_PROJECT_ERROR.getCode(), DELETE_PROJECT_ERROR.getMsg());
}
} }
/** /**
@ -210,22 +190,18 @@ public class ProjectController extends BaseController {
* @param userId user id * @param userId user id
* @return the projects which user have not permission to see * @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({ @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") @GetMapping(value = "/unauth-project")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_UNAUTHORIZED_PROJECT_ERROR)
public Result queryUnauthorizedProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryUnauthorizedProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("userId") Integer userId) { @RequestParam("userId") Integer userId) {
try {
logger.info("login user {}, query unauthorized project by user id: {}.", loginUser.getUserName(), userId); logger.info("login user {}, query unauthorized project by user id: {}.", loginUser.getUserName(), userId);
Map<String, Object> result = projectService.queryUnauthorizedProject(loginUser, userId); Map<String, Object> result = projectService.queryUnauthorizedProject(loginUser, userId);
return returnDataList(result); 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());
}
} }
@ -236,70 +212,58 @@ public class ProjectController extends BaseController {
* @param userId user id * @param userId user id
* @return projects which the user have permission to see, Except for items created by this user * @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({ @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") @GetMapping(value = "/authed-project")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_AUTHORIZED_PROJECT)
public Result queryAuthorizedProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryAuthorizedProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("userId") Integer userId) { @RequestParam("userId") Integer userId) {
try {
logger.info("login user {}, query authorized project by user id: {}.", loginUser.getUserName(), userId); logger.info("login user {}, query authorized project by user id: {}.", loginUser.getUserName(), userId);
Map<String, Object> result = projectService.queryAuthorizedProject(loginUser, userId); Map<String, Object> result = projectService.queryAuthorizedProject(loginUser, userId);
return returnDataList(result); return returnDataList(result);
} catch (Exception e) {
logger.error(QUERY_AUTHORIZED_PROJECT.getMsg(), e);
return error(QUERY_AUTHORIZED_PROJECT.getCode(), QUERY_AUTHORIZED_PROJECT.getMsg());
}
} }
/** /**
* import process definition * import process definition
*
* @param loginUser login user * @param loginUser login user
* @param file resource file * @param file resource file
* @param projectName project name * @param projectName project name
* @return import result code * @return import result code
*/ */
@ApiOperation(value = "importProcessDefinition", notes= "EXPORT_PROCCESS_DEFINITION_NOTES") @ApiOperation(value = "importProcessDefinition", notes = "EXPORT_PROCCESS_DEFINITION_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "file", value = "RESOURCE_FILE", required = true, dataType = "MultipartFile") @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, public Result importProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("file") MultipartFile file, @RequestParam("file") MultipartFile file,
@RequestParam("projectName") String projectName){ @RequestParam("projectName") String projectName) {
try{
logger.info("import process definition by id, login user:{}, project: {}", logger.info("import process definition by id, login user:{}, project: {}",
loginUser.getUserName(), projectName); loginUser.getUserName(), projectName);
Map<String, Object> result = processDefinitionService.importProcessDefinition(loginUser, file, projectName); Map<String, Object> result = processDefinitionService.importProcessDefinition(loginUser, file, projectName);
return returnDataList(result); 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());
}
} }
/** /**
* query all project list * query all project list
*
* @param loginUser login user * @param loginUser login user
* @return all project list * @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") @GetMapping(value = "/query-project-list")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR)
public Result queryAllProjectList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { public Result queryAllProjectList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
try {
logger.info("login user {}, query all project list", loginUser.getUserName()); logger.info("login user {}, query all project list", loginUser.getUserName());
Map<String, Object> result = projectService.queryAllProjectList(); Map<String, Object> result = projectService.queryAllProjectList();
return returnDataList(result); 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());
}
} }
} }

97
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.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.QueueService; import org.apache.dolphinscheduler.api.service.QueueService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
@ -36,6 +37,8 @@ import springfox.documentation.annotations.ApiIgnore;
import java.util.Map; import java.util.Map;
import static org.apache.dolphinscheduler.api.enums.Status.*;
/** /**
* queue controller * queue controller
@ -43,7 +46,7 @@ import java.util.Map;
@Api(tags = "QUEUE_TAG", position = 1) @Api(tags = "QUEUE_TAG", position = 1)
@RestController @RestController
@RequestMapping("/queue") @RequestMapping("/queue")
public class QueueController extends BaseController{ public class QueueController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(QueueController.class); private static final Logger logger = LoggerFactory.getLogger(QueueController.class);
@ -53,57 +56,51 @@ public class QueueController extends BaseController{
/** /**
* query queue list * query queue list
*
* @param loginUser login user * @param loginUser login user
* @return queue list * @return queue list
*/ */
@ApiOperation(value = "queryList", notes= "QUERY_QUEUE_LIST_NOTES") @ApiOperation(value = "queryList", notes = "QUERY_QUEUE_LIST_NOTES")
@GetMapping(value="/list") @GetMapping(value = "/list")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
public Result queryList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser){ @ApiException(QUERY_QUEUE_LIST_ERROR)
try{ public Result queryList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
logger.info("login user {}, query queue list", loginUser.getUserName()); logger.info("login user {}, query queue list", loginUser.getUserName());
Map<String, Object> result = queueService.queryList(loginUser); Map<String, Object> result = queueService.queryList(loginUser);
return returnDataList(result); 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());
}
} }
/** /**
* query queue list paging * query queue list paging
*
* @param loginUser login user * @param loginUser login user
* @param pageNo page number * @param pageNo page number
* @param searchVal search value * @param searchVal search value
* @param pageSize page size * @param pageSize page size
* @return queue list * @return queue list
*/ */
@ApiOperation(value = "queryQueueListPaging", notes= "QUERY_QUEUE_LIST_PAGING_NOTES") @ApiOperation(value = "queryQueueListPaging", notes = "QUERY_QUEUE_LIST_PAGING_NOTES")
@ApiImplicitParams({ @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 = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"),
@ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType ="Int",example = "20") @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20")
}) })
@GetMapping(value="/list-paging") @GetMapping(value = "/list-paging")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_QUEUE_LIST_ERROR)
public Result queryQueueListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryQueueListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageSize") Integer pageSize){ @RequestParam("pageSize") Integer pageSize) {
try{ logger.info("login user {}, query queue list,search value:{}", loginUser.getUserName(), searchVal);
logger.info("login user {}, query queue list,search value:{}", loginUser.getUserName(),searchVal);
Map<String, Object> result = checkPageParams(pageNo, pageSize); Map<String, Object> result = checkPageParams(pageNo, pageSize);
if(result.get(Constants.STATUS) != Status.SUCCESS){ if (result.get(Constants.STATUS) != Status.SUCCESS) {
return returnDataListPaging(result); return returnDataListPaging(result);
} }
searchVal = ParameterUtils.handleEscapes(searchVal); searchVal = ParameterUtils.handleEscapes(searchVal);
result = queueService.queryList(loginUser,searchVal,pageNo,pageSize); result = queueService.queryList(loginUser, searchVal, pageNo, pageSize);
return returnDataListPaging(result); 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());
}
} }
/** /**
@ -114,26 +111,21 @@ public class QueueController extends BaseController{
* @param queueName queue name * @param queueName queue name
* @return create result * @return create result
*/ */
@ApiOperation(value = "createQueue", notes= "CREATE_QUEUE_NOTES") @ApiOperation(value = "createQueue", notes = "CREATE_QUEUE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "queue", value = "YARN_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") @ApiImplicitParam(name = "queueName", value = "QUEUE_NAME", required = true, dataType = "String")
}) })
@PostMapping(value = "/create") @PostMapping(value = "/create")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_QUEUE_ERROR)
public Result createQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result createQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "queue") String queue, @RequestParam(value = "queue") String queue,
@RequestParam(value = "queueName") String queueName) { @RequestParam(value = "queueName") String queueName) {
logger.info("login user {}, create queue, queue: {}, queueName: {}", logger.info("login user {}, create queue, queue: {}, queueName: {}",
loginUser.getUserName(), queue, queueName); loginUser.getUserName(), queue, queueName);
try { Map<String, Object> result = queueService.createQueue(loginUser, queue, queueName);
Map<String, Object> result = queueService.createQueue(loginUser,queue,queueName);
return returnDataList(result); 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());
}
} }
/** /**
@ -145,28 +137,23 @@ public class QueueController extends BaseController{
* @param queueName queue name * @param queueName queue name
* @return update result code * @return update result code
*/ */
@ApiOperation(value = "updateQueue", notes= "UPDATE_QUEUE_NOTES") @ApiOperation(value = "updateQueue", notes = "UPDATE_QUEUE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "QUEUE_ID", required = true, dataType ="Int", example = "100"), @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 = "queue", value = "YARN_QUEUE_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "queueName", value = "QUEUE_NAME",required = true, dataType ="String") @ApiImplicitParam(name = "queueName", value = "QUEUE_NAME", required = true, dataType = "String")
}) })
@PostMapping(value = "/update") @PostMapping(value = "/update")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@ApiException(UPDATE_QUEUE_ERROR)
public Result updateQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result updateQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int id, @RequestParam(value = "id") int id,
@RequestParam(value = "queue") String queue, @RequestParam(value = "queue") String queue,
@RequestParam(value = "queueName") String queueName) { @RequestParam(value = "queueName") String queueName) {
logger.info("login user {}, update queue, id: {}, queue: {}, queueName: {}", logger.info("login user {}, update queue, id: {}, queue: {}, queueName: {}",
loginUser.getUserName(), id,queue, queueName); loginUser.getUserName(), id, queue, queueName);
try { Map<String, Object> result = queueService.updateQueue(loginUser, id, queue, queueName);
Map<String, Object> result = queueService.updateQueue(loginUser,id,queue,queueName);
return returnDataList(result); 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());
}
} }
/** /**
@ -177,27 +164,23 @@ public class QueueController extends BaseController{
* @param queueName queue name * @param queueName queue name
* @return true if the queue name not exists, otherwise return false * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "QUEUE_ID", required = true, dataType ="Int", example = "100"), @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 = "queue", value = "YARN_QUEUE_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "queueName", value = "QUEUE_NAME",required = true, dataType ="String") @ApiImplicitParam(name = "queueName", value = "QUEUE_NAME", required = true, dataType = "String")
}) })
@PostMapping(value = "/verify-queue") @PostMapping(value = "/verify-queue")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(VERIFY_QUEUE_ERROR)
public Result verifyQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result verifyQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value ="queue") String queue, @RequestParam(value = "queue") String queue,
@RequestParam(value ="queueName") String queueName @RequestParam(value = "queueName") String queueName
) { ) {
try{
logger.info("login user {}, verfiy queue: {} queue name: {}", logger.info("login user {}, verfiy queue: {} queue name: {}",
loginUser.getUserName(),queue,queueName); loginUser.getUserName(), queue, queueName);
return queueService.verifyQueue(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());
}
} }

465
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java

@ -17,6 +17,7 @@
package org.apache.dolphinscheduler.api.controller; package org.apache.dolphinscheduler.api.controller;
import org.apache.dolphinscheduler.api.enums.Status; 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.ResourcesService;
import org.apache.dolphinscheduler.api.service.UdfFuncService; import org.apache.dolphinscheduler.api.service.UdfFuncService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
@ -44,13 +45,14 @@ import springfox.documentation.annotations.ApiIgnore;
import java.util.Map; import java.util.Map;
import static org.apache.dolphinscheduler.api.enums.Status.*; import static org.apache.dolphinscheduler.api.enums.Status.*;
/** /**
* resources controller * resources controller
*/ */
@Api(tags = "RESOURCES_TAG", position = 1) @Api(tags = "RESOURCES_TAG", position = 1)
@RestController @RestController
@RequestMapping("resources") @RequestMapping("resources")
public class ResourcesController extends BaseController{ public class ResourcesController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(ResourcesController.class); private static final Logger logger = LoggerFactory.getLogger(ResourcesController.class);
@ -71,7 +73,6 @@ public class ResourcesController extends BaseController{
*/ */
/** /**
*
* @param loginUser login user * @param loginUser login user
* @param type type * @param type type
* @param alias alias * @param alias alias
@ -80,28 +81,24 @@ public class ResourcesController extends BaseController{
* @param currentDir current directory * @param currentDir current directory
* @return * @return
*/ */
@ApiOperation(value = "createDirctory", notes= "CREATE_RESOURCE_NOTES") @ApiOperation(value = "createDirctory", notes = "CREATE_RESOURCE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType ="ResourceType"), @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"),
@ApiImplicitParam(name = "name", value = "RESOURCE_NAME", required = true, dataType ="String"), @ApiImplicitParam(name = "name", value = "RESOURCE_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "description", value = "RESOURCE_DESC", dataType ="String"), @ApiImplicitParam(name = "description", value = "RESOURCE_DESC", dataType = "String"),
@ApiImplicitParam(name = "file", value = "RESOURCE_FILE", required = true, dataType = "MultipartFile") @ApiImplicitParam(name = "file", value = "RESOURCE_FILE", required = true, dataType = "MultipartFile")
}) })
@PostMapping(value = "/directory/create") @PostMapping(value = "/directory/create")
@ApiException(CREATE_RESOURCE_ERROR)
public Result createDirectory(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result createDirectory(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "type") ResourceType type, @RequestParam(value = "type") ResourceType type,
@RequestParam(value ="name") String alias, @RequestParam(value = "name") String alias,
@RequestParam(value = "description", required = false) String description, @RequestParam(value = "description", required = false) String description,
@RequestParam(value ="pid") int pid, @RequestParam(value = "pid") int pid,
@RequestParam(value ="currentDir") String currentDir) { @RequestParam(value = "currentDir") String currentDir) {
try {
logger.info("login user {}, create resource, type: {}, resource alias: {}, desc: {}, file: {},{}", logger.info("login user {}, create resource, type: {}, resource alias: {}, desc: {}, file: {},{}",
loginUser.getUserName(),type, alias, description,pid,currentDir); loginUser.getUserName(), type, alias, description, pid, currentDir);
return resourceService.createDirectory(loginUser,alias, description,type ,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());
}
} }
/** /**
@ -114,29 +111,25 @@ public class ResourcesController extends BaseController{
* @param file file * @param file file
* @return create result code * @return create result code
*/ */
@ApiOperation(value = "createResource", notes= "CREATE_RESOURCE_NOTES") @ApiOperation(value = "createResource", notes = "CREATE_RESOURCE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType ="ResourceType"), @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"),
@ApiImplicitParam(name = "name", value = "RESOURCE_NAME", required = true, dataType ="String"), @ApiImplicitParam(name = "name", value = "RESOURCE_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "description", value = "RESOURCE_DESC", dataType ="String"), @ApiImplicitParam(name = "description", value = "RESOURCE_DESC", dataType = "String"),
@ApiImplicitParam(name = "file", value = "RESOURCE_FILE", required = true, dataType = "MultipartFile") @ApiImplicitParam(name = "file", value = "RESOURCE_FILE", required = true, dataType = "MultipartFile")
}) })
@PostMapping(value = "/create") @PostMapping(value = "/create")
@ApiException(CREATE_RESOURCE_ERROR)
public Result createResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result createResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "type") ResourceType type, @RequestParam(value = "type") ResourceType type,
@RequestParam(value ="name") String alias, @RequestParam(value = "name") String alias,
@RequestParam(value = "description", required = false) String description, @RequestParam(value = "description", required = false) String description,
@RequestParam("file") MultipartFile file, @RequestParam("file") MultipartFile file,
@RequestParam(value ="pid") int pid, @RequestParam(value = "pid") int pid,
@RequestParam(value ="currentDir") String currentDir) { @RequestParam(value = "currentDir") String currentDir) {
try {
logger.info("login user {}, create resource, type: {}, resource alias: {}, desc: {}, file: {},{}", logger.info("login user {}, create resource, type: {}, resource alias: {}, desc: {}, file: {},{}",
loginUser.getUserName(),type, alias, description, file.getName(), file.getOriginalFilename()); loginUser.getUserName(), type, alias, description, file.getName(), file.getOriginalFilename());
return resourceService.createResource(loginUser,alias, description,type ,file,pid,currentDir); 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());
}
} }
/** /**
@ -149,27 +142,23 @@ public class ResourcesController extends BaseController{
* @param description description * @param description description
* @return update result code * @return update result code
*/ */
@ApiOperation(value = "updateResource", notes= "UPDATE_RESOURCE_NOTES") @ApiOperation(value = "updateResource", notes = "UPDATE_RESOURCE_NOTES")
@ApiImplicitParams({ @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"),
@ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType ="ResourceType"), @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"),
@ApiImplicitParam(name = "name", value = "RESOURCE_NAME", required = true, dataType ="String"), @ApiImplicitParam(name = "name", value = "RESOURCE_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "description", value = "RESOURCE_DESC", dataType ="String") @ApiImplicitParam(name = "description", value = "RESOURCE_DESC", dataType = "String")
}) })
@PostMapping(value = "/update") @PostMapping(value = "/update")
@ApiException(UPDATE_RESOURCE_ERROR)
public Result updateResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, 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 = "type") ResourceType type,
@RequestParam(value ="name")String alias, @RequestParam(value = "name") String alias,
@RequestParam(value = "description", required = false) String description) { @RequestParam(value = "description", required = false) String description) {
try {
logger.info("login user {}, update resource, type: {}, resource alias: {}, desc: {}", logger.info("login user {}, update resource, type: {}, resource alias: {}, desc: {}",
loginUser.getUserName(),type, alias, description); loginUser.getUserName(), type, alias, description);
return resourceService.updateResource(loginUser,resourceId,alias,description,type); 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());
}
} }
/** /**
@ -179,23 +168,19 @@ public class ResourcesController extends BaseController{
* @param type resource type * @param type resource type
* @return resource list * @return resource list
*/ */
@ApiOperation(value = "queryResourceList", notes= "QUERY_RESOURCE_LIST_NOTES") @ApiOperation(value = "queryResourceList", notes = "QUERY_RESOURCE_LIST_NOTES")
@ApiImplicitParams({ @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) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_RESOURCES_LIST_ERROR)
public Result queryResourceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryResourceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value ="type") ResourceType type @RequestParam(value = "type") ResourceType type
){ ) {
try{
logger.info("query resource list, login user:{}, resource type:{}", loginUser.getUserName(), type); logger.info("query resource list, login user:{}, resource type:{}", loginUser.getUserName(), type);
Map<String, Object> result = resourceService.queryResourceList(loginUser, type); Map<String, Object> result = resourceService.queryResourceList(loginUser, type);
return returnDataList(result); 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());
}
} }
/** /**
@ -208,38 +193,34 @@ public class ResourcesController extends BaseController{
* @param pageSize page size * @param pageSize page size
* @return resource list page * @return resource list page
*/ */
@ApiOperation(value = "queryResourceListPaging", notes= "QUERY_RESOURCE_LIST_PAGING_NOTES") @ApiOperation(value = "queryResourceListPaging", notes = "QUERY_RESOURCE_LIST_PAGING_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType ="ResourceType"), @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"),
@ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType ="int"), @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "int"),
@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 = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"),
@ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType ="Int",example = "20") @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20")
}) })
@GetMapping(value="/list-paging") @GetMapping(value = "/list-paging")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_RESOURCES_LIST_PAGING)
public Result queryResourceListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryResourceListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value ="type") ResourceType type, @RequestParam(value = "type") ResourceType type,
@RequestParam(value ="id") int id, @RequestParam(value = "id") int id,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageSize") Integer pageSize @RequestParam("pageSize") Integer pageSize
){ ) {
try{
logger.info("query resource list, login user:{}, resource type:{}, search value:{}", logger.info("query resource list, login user:{}, resource type:{}, search value:{}",
loginUser.getUserName(), type, searchVal); loginUser.getUserName(), type, searchVal);
Map<String, Object> result = checkPageParams(pageNo, pageSize); Map<String, Object> result = checkPageParams(pageNo, pageSize);
if(result.get(Constants.STATUS) != Status.SUCCESS){ if (result.get(Constants.STATUS) != Status.SUCCESS) {
return returnDataListPaging(result); return returnDataListPaging(result);
} }
searchVal = ParameterUtils.handleEscapes(searchVal); searchVal = ParameterUtils.handleEscapes(searchVal);
result = resourceService.queryResourceListPaging(loginUser,id,type,searchVal,pageNo, pageSize); result = resourceService.queryResourceListPaging(loginUser, id, type, searchVal, pageNo, pageSize);
return returnDataListPaging(result); 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());
}
} }
@ -250,23 +231,19 @@ public class ResourcesController extends BaseController{
* @param resourceId resource id * @param resourceId resource id
* @return delete result code * @return delete result code
*/ */
@ApiOperation(value = "deleteResource", notes= "DELETE_RESOURCE_BY_ID_NOTES") @ApiOperation(value = "deleteResource", notes = "DELETE_RESOURCE_BY_ID_NOTES")
@ApiImplicitParams({ @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") @GetMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_RESOURCE_ERROR)
public Result deleteResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result deleteResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value ="id") int resourceId @RequestParam(value = "id") int resourceId
) { ) throws Exception {
try{
logger.info("login user {}, delete resource id: {}", logger.info("login user {}, delete resource id: {}",
loginUser.getUserName(),resourceId); loginUser.getUserName(), resourceId);
return resourceService.delete(loginUser,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());
}
} }
@ -278,26 +255,22 @@ public class ResourcesController extends BaseController{
* @param type resource type * @param type resource type
* @return true if the resource name not exists, otherwise return false * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType ="ResourceType"), @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"),
@ApiImplicitParam(name = "fullName", value = "RESOURCE_FULL_NAME", required = true, dataType ="String") @ApiImplicitParam(name = "fullName", value = "RESOURCE_FULL_NAME", required = true, dataType = "String")
}) })
@GetMapping(value = "/verify-name") @GetMapping(value = "/verify-name")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(VERIFY_RESOURCE_BY_NAME_AND_TYPE_ERROR)
public Result verifyResourceName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result verifyResourceName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value ="fullName") String fullName, @RequestParam(value = "fullName") String fullName,
@RequestParam(value ="type") ResourceType type @RequestParam(value = "type") ResourceType type
) { ) {
try {
logger.info("login user {}, verfiy resource alias: {},resource type: {}", logger.info("login user {}, verfiy resource alias: {},resource type: {}",
loginUser.getUserName(), fullName,type); loginUser.getUserName(), fullName, type);
return resourceService.verifyResourceName(fullName,type,loginUser); 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());
}
} }
/** /**
@ -307,23 +280,19 @@ public class ResourcesController extends BaseController{
* @param type resource type * @param type resource type
* @return resource list * @return resource list
*/ */
@ApiOperation(value = "queryResourceJarList", notes= "QUERY_RESOURCE_LIST_NOTES") @ApiOperation(value = "queryResourceJarList", notes = "QUERY_RESOURCE_LIST_NOTES")
@ApiImplicitParams({ @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) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_RESOURCES_LIST_ERROR)
public Result queryResourceJarList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryResourceJarList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value ="type") ResourceType type @RequestParam(value = "type") ResourceType type
){ ) {
try{
logger.info("query resource list, login user:{}, resource type:{}", loginUser.getUserName(), type.toString()); logger.info("query resource list, login user:{}, resource type:{}", loginUser.getUserName(), type.toString());
Map<String, Object> result = resourceService.queryResourceJarList(loginUser, type); Map<String, Object> result = resourceService.queryResourceJarList(loginUser, type);
return returnDataList(result); 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());
}
} }
/** /**
@ -334,27 +303,23 @@ public class ResourcesController extends BaseController{
* @param type resource type * @param type resource type
* @return true if the resource name not exists, otherwise return false * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType ="ResourceType"), @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"),
@ApiImplicitParam(name = "fullName", value = "RESOURCE_FULL_NAME", required = true, dataType ="String") @ApiImplicitParam(name = "fullName", value = "RESOURCE_FULL_NAME", required = true, dataType = "String")
}) })
@GetMapping(value = "/queryResource") @GetMapping(value = "/queryResource")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(RESOURCE_NOT_EXIST)
public Result queryResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value ="fullName",required = false) String fullName, @RequestParam(value = "fullName", required = false) String fullName,
@RequestParam(value ="id",required = false) Integer id, @RequestParam(value = "id", required = false) Integer id,
@RequestParam(value ="type") ResourceType type @RequestParam(value = "type") ResourceType type
) { ) {
try {
logger.info("login user {}, query resource by full name: {} or id: {},resource type: {}", logger.info("login user {}, query resource by full name: {} or id: {},resource type: {}",
loginUser.getUserName(), fullName,id,type); loginUser.getUserName(), fullName, id, type);
return resourceService.queryResource(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());
}
} }
/** /**
@ -366,27 +331,23 @@ public class ResourcesController extends BaseController{
* @param limit limit * @param limit limit
* @return resource content * @return resource content
*/ */
@ApiOperation(value = "viewResource", notes= "VIEW_RESOURCE_BY_ID_NOTES") @ApiOperation(value = "viewResource", notes = "VIEW_RESOURCE_BY_ID_NOTES")
@ApiImplicitParams({ @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"),
@ApiImplicitParam(name = "skipLineNum", value = "SKIP_LINE_NUM", 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 = "limit", value = "LIMIT", required = true, dataType = "Int", example = "100")
}) })
@GetMapping(value = "/view") @GetMapping(value = "/view")
@ApiException(VIEW_RESOURCE_FILE_ON_LINE_ERROR)
public Result viewResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result viewResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int resourceId, @RequestParam(value = "id") int resourceId,
@RequestParam(value = "skipLineNum") int skipLineNum, @RequestParam(value = "skipLineNum") int skipLineNum,
@RequestParam(value = "limit") int limit @RequestParam(value = "limit") int limit
) { ) {
try{
logger.info("login user {}, view resource : {}, skipLineNum {} , limit {}", logger.info("login user {}, view resource : {}, skipLineNum {} , limit {}",
loginUser.getUserName(),resourceId,skipLineNum,limit); loginUser.getUserName(), resourceId, skipLineNum, limit);
return resourceService.readResource(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());
}
} }
/** /**
@ -400,36 +361,32 @@ public class ResourcesController extends BaseController{
* @param content content * @param content content
* @return create result code * @return create result code
*/ */
@ApiOperation(value = "onlineCreateResource", notes= "ONLINE_CREATE_RESOURCE_NOTES") @ApiOperation(value = "onlineCreateResource", notes = "ONLINE_CREATE_RESOURCE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType ="ResourceType"), @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"),
@ApiImplicitParam(name = "fileName", value = "RESOURCE_NAME",required = true, dataType ="String"), @ApiImplicitParam(name = "fileName", value = "RESOURCE_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "suffix", value = "SUFFIX", required = true, dataType ="String"), @ApiImplicitParam(name = "suffix", value = "SUFFIX", required = true, dataType = "String"),
@ApiImplicitParam(name = "description", value = "RESOURCE_DESC", dataType ="String"), @ApiImplicitParam(name = "description", value = "RESOURCE_DESC", dataType = "String"),
@ApiImplicitParam(name = "content", value = "CONTENT",required = true, dataType ="String") @ApiImplicitParam(name = "content", value = "CONTENT", required = true, dataType = "String")
}) })
@PostMapping(value = "/online-create") @PostMapping(value = "/online-create")
@ApiException(CREATE_RESOURCE_FILE_ON_LINE_ERROR)
public Result onlineCreateResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result onlineCreateResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "type") ResourceType type, @RequestParam(value = "type") ResourceType type,
@RequestParam(value ="fileName")String fileName, @RequestParam(value = "fileName") String fileName,
@RequestParam(value ="suffix")String fileSuffix, @RequestParam(value = "suffix") String fileSuffix,
@RequestParam(value = "description", required = false) String description, @RequestParam(value = "description", required = false) String description,
@RequestParam(value = "content") String content, @RequestParam(value = "content") String content,
@RequestParam(value ="pid") int pid, @RequestParam(value = "pid") int pid,
@RequestParam(value ="currentDir") String currentDir @RequestParam(value = "currentDir") String currentDir
) { ) {
try{
logger.info("login user {}, online create resource! fileName : {}, type : {}, suffix : {},desc : {},content : {}", logger.info("login user {}, online create resource! fileName : {}, type : {}, suffix : {},desc : {},content : {}",
loginUser.getUserName(),fileName,type,fileSuffix,description,content,pid,currentDir); loginUser.getUserName(), fileName, type, fileSuffix, description, content, pid, currentDir);
if(StringUtils.isEmpty(content)){ if (StringUtils.isEmpty(content)) {
logger.error("resource file contents are not allowed to be empty"); 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 error(Status.RESOURCE_FILE_IS_EMPTY.getCode(), RESOURCE_FILE_IS_EMPTY.getMsg());
} }
return resourceService.onlineCreateResource(loginUser,type,fileName,fileSuffix,description,content,pid,currentDir); 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());
}
} }
/** /**
@ -440,28 +397,24 @@ public class ResourcesController extends BaseController{
* @param content content * @param content content
* @return update result code * @return update result code
*/ */
@ApiOperation(value = "updateResourceContent", notes= "UPDATE_RESOURCE_NOTES") @ApiOperation(value = "updateResourceContent", notes = "UPDATE_RESOURCE_NOTES")
@ApiImplicitParams({ @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"),
@ApiImplicitParam(name = "content", value = "CONTENT",required = true, dataType ="String") @ApiImplicitParam(name = "content", value = "CONTENT", required = true, dataType = "String")
}) })
@PostMapping(value = "/update-content") @PostMapping(value = "/update-content")
@ApiException(EDIT_RESOURCE_FILE_ON_LINE_ERROR)
public Result updateResourceContent(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result updateResourceContent(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int resourceId, @RequestParam(value = "id") int resourceId,
@RequestParam(value = "content") String content @RequestParam(value = "content") String content
) { ) {
try{
logger.info("login user {}, updateProcessInstance resource : {}", logger.info("login user {}, updateProcessInstance resource : {}",
loginUser.getUserName(),resourceId); loginUser.getUserName(), resourceId);
if(StringUtils.isEmpty(content)){ if (StringUtils.isEmpty(content)) {
logger.error("The resource file contents are not allowed to be empty"); 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 error(Status.RESOURCE_FILE_IS_EMPTY.getCode(), RESOURCE_FILE_IS_EMPTY.getMsg());
} }
return resourceService.updateResourceContent(resourceId,content); 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());
}
} }
/** /**
@ -471,15 +424,15 @@ public class ResourcesController extends BaseController{
* @param resourceId resource id * @param resourceId resource id
* @return resource content * @return resource content
*/ */
@ApiOperation(value = "downloadResource", notes= "DOWNLOAD_RESOURCE_NOTES") @ApiOperation(value = "downloadResource", notes = "DOWNLOAD_RESOURCE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType ="Int", example = "100") @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100")
}) })
@GetMapping(value = "/download") @GetMapping(value = "/download")
@ResponseBody @ResponseBody
@ApiException(DOWNLOAD_RESOURCE_FILE_ERROR)
public ResponseEntity downloadResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public ResponseEntity downloadResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int resourceId) { @RequestParam(value = "id") int resourceId) throws Exception {
try{
logger.info("login user {}, download resource : {}", logger.info("login user {}, download resource : {}",
loginUser.getUserName(), resourceId); loginUser.getUserName(), resourceId);
Resource file = resourceService.downloadResource(resourceId); Resource file = resourceService.downloadResource(resourceId);
@ -490,18 +443,12 @@ public class ResourcesController extends BaseController{
.ok() .ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getFilename() + "\"") .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getFilename() + "\"")
.body(file); .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());
}
} }
/** /**
* create udf function * create udf function
*
* @param loginUser login user * @param loginUser login user
* @param type udf type * @param type udf type
* @param funcName function name * @param funcName function name
@ -512,35 +459,31 @@ public class ResourcesController extends BaseController{
* @param resourceId resource id * @param resourceId resource id
* @return create result code * @return create result code
*/ */
@ApiOperation(value = "createUdfFunc", notes= "CREATE_UDF_FUNCTION_NOTES") @ApiOperation(value = "createUdfFunc", notes = "CREATE_UDF_FUNCTION_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "type", value = "UDF_TYPE", required = true, dataType ="UdfType"), @ApiImplicitParam(name = "type", value = "UDF_TYPE", required = true, dataType = "UdfType"),
@ApiImplicitParam(name = "funcName", value = "FUNC_NAME",required = true, dataType ="String"), @ApiImplicitParam(name = "funcName", value = "FUNC_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "suffix", value = "CLASS_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 = "argTypes", value = "ARG_TYPES", dataType = "String"),
@ApiImplicitParam(name = "database", value = "DATABASE_NAME", dataType ="String"), @ApiImplicitParam(name = "database", value = "DATABASE_NAME", dataType = "String"),
@ApiImplicitParam(name = "description", value = "UDF_DESC", dataType ="String"), @ApiImplicitParam(name = "description", value = "UDF_DESC", dataType = "String"),
@ApiImplicitParam(name = "resourceId", value = "RESOURCE_ID", required = true, dataType ="Int", example = "100") @ApiImplicitParam(name = "resourceId", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100")
}) })
@PostMapping(value = "/udf-func/create") @PostMapping(value = "/udf-func/create")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_UDF_FUNCTION_ERROR)
public Result createUdfFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result createUdfFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "type") UdfType type, @RequestParam(value = "type") UdfType type,
@RequestParam(value ="funcName")String funcName, @RequestParam(value = "funcName") String funcName,
@RequestParam(value ="className")String className, @RequestParam(value = "className") String className,
@RequestParam(value ="argTypes", required = false)String argTypes, @RequestParam(value = "argTypes", required = false) String argTypes,
@RequestParam(value ="database", required = false)String database, @RequestParam(value = "database", required = false) String database,
@RequestParam(value = "description", required = false) String description, @RequestParam(value = "description", required = false) String description,
@RequestParam(value = "resourceId") int resourceId) { @RequestParam(value = "resourceId") int resourceId) {
logger.info("login user {}, create udf function, type: {}, funcName: {},argTypes: {} ,database: {},desc: {},resourceId: {}", logger.info("login user {}, create udf function, type: {}, funcName: {},argTypes: {} ,database: {},desc: {},resourceId: {}",
loginUser.getUserName(),type, funcName, argTypes,database,description, resourceId); loginUser.getUserName(), type, funcName, argTypes, database, description, resourceId);
try { return udfFuncService.createUdfFunction(loginUser, funcName, className, argTypes, database, description, type, resourceId);
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());
}
} }
/** /**
@ -550,24 +493,20 @@ public class ResourcesController extends BaseController{
* @param id resource id * @param id resource id
* @return udf function detail * @return udf function detail
*/ */
@ApiOperation(value = "viewUIUdfFunction", notes= "VIEW_UDF_FUNCTION_NOTES") @ApiOperation(value = "viewUIUdfFunction", notes = "VIEW_UDF_FUNCTION_NOTES")
@ApiImplicitParams({ @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") @GetMapping(value = "/udf-func/update-ui")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(VIEW_UDF_FUNCTION_ERROR)
public Result viewUIUdfFunction(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, 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{}", logger.info("login user {}, query udf{}",
loginUser.getUserName(), id); loginUser.getUserName(), id);
try {
Map<String, Object> map = udfFuncService.queryUdfFuncDetail(id); Map<String, Object> map = udfFuncService.queryUdfFuncDetail(id);
return returnDataList(map); 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());
}
} }
/** /**
@ -584,36 +523,32 @@ public class ResourcesController extends BaseController{
* @param udfFuncId udf function id * @param udfFuncId udf function id
* @return update result code * @return update result code
*/ */
@ApiOperation(value = "updateUdfFunc", notes= "UPDATE_UDF_FUNCTION_NOTES") @ApiOperation(value = "updateUdfFunc", notes = "UPDATE_UDF_FUNCTION_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "type", value = "UDF_TYPE", required = true, dataType ="UdfType"), @ApiImplicitParam(name = "type", value = "UDF_TYPE", required = true, dataType = "UdfType"),
@ApiImplicitParam(name = "funcName", value = "FUNC_NAME",required = true, dataType ="String"), @ApiImplicitParam(name = "funcName", value = "FUNC_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "suffix", value = "CLASS_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 = "argTypes", value = "ARG_TYPES", dataType = "String"),
@ApiImplicitParam(name = "database", value = "DATABASE_NAME", dataType ="String"), @ApiImplicitParam(name = "database", value = "DATABASE_NAME", dataType = "String"),
@ApiImplicitParam(name = "description", value = "UDF_DESC", dataType ="String"), @ApiImplicitParam(name = "description", value = "UDF_DESC", dataType = "String"),
@ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType ="Int", example = "100") @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100")
}) })
@PostMapping(value = "/udf-func/update") @PostMapping(value = "/udf-func/update")
@ApiException(UPDATE_UDF_FUNCTION_ERROR)
public Result updateUdfFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result updateUdfFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int udfFuncId, @RequestParam(value = "id") int udfFuncId,
@RequestParam(value = "type") UdfType type, @RequestParam(value = "type") UdfType type,
@RequestParam(value ="funcName")String funcName, @RequestParam(value = "funcName") String funcName,
@RequestParam(value ="className")String className, @RequestParam(value = "className") String className,
@RequestParam(value ="argTypes", required = false)String argTypes, @RequestParam(value = "argTypes", required = false) String argTypes,
@RequestParam(value ="database", required = false)String database, @RequestParam(value = "database", required = false) String database,
@RequestParam(value = "description", required = false) String description, @RequestParam(value = "description", required = false) String description,
@RequestParam(value = "resourceId") int resourceId) { @RequestParam(value = "resourceId") int resourceId) {
try {
logger.info("login user {}, updateProcessInstance udf function id: {},type: {}, funcName: {},argTypes: {} ,database: {},desc: {},resourceId: {}", logger.info("login user {}, updateProcessInstance udf function id: {},type: {}, funcName: {},argTypes: {} ,database: {},desc: {},resourceId: {}",
loginUser.getUserName(),udfFuncId,type, funcName, argTypes,database,description, resourceId); loginUser.getUserName(), udfFuncId, type, funcName, argTypes, database, description, resourceId);
Map<String, Object> result = udfFuncService.updateUdfFunc(udfFuncId,funcName,className,argTypes,database,description,type,resourceId); Map<String, Object> result = udfFuncService.updateUdfFunc(udfFuncId, funcName, className, argTypes, database, description, type, resourceId);
return returnDataList(result); 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());
}
} }
/** /**
@ -625,33 +560,29 @@ public class ResourcesController extends BaseController{
* @param pageSize page size * @param pageSize page size
* @return udf function list page * @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({ @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 = "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) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_UDF_FUNCTION_LIST_PAGING_ERROR)
public Result queryUdfFuncList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryUdfFuncList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageSize") Integer pageSize @RequestParam("pageSize") Integer pageSize
){ ) {
try{
logger.info("query udf functions list, login user:{},search value:{}", logger.info("query udf functions list, login user:{},search value:{}",
loginUser.getUserName(), searchVal); loginUser.getUserName(), searchVal);
Map<String, Object> result = checkPageParams(pageNo, pageSize); Map<String, Object> result = checkPageParams(pageNo, pageSize);
if(result.get(Constants.STATUS) != Status.SUCCESS){ if (result.get(Constants.STATUS) != Status.SUCCESS) {
return returnDataListPaging(result); return returnDataListPaging(result);
} }
result = udfFuncService.queryUdfFuncListPaging(loginUser,searchVal,pageNo, pageSize); result = udfFuncService.queryUdfFuncListPaging(loginUser, searchVal, pageNo, pageSize);
return returnDataListPaging(result); 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());
}
} }
/** /**
@ -661,22 +592,18 @@ public class ResourcesController extends BaseController{
* @param type resource type * @param type resource type
* @return resource list * @return resource list
*/ */
@ApiOperation(value = "queryResourceList", notes= "QUERY_RESOURCE_LIST_NOTES") @ApiOperation(value = "queryResourceList", notes = "QUERY_RESOURCE_LIST_NOTES")
@ApiImplicitParams({ @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) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_DATASOURCE_BY_TYPE_ERROR)
public Result queryResourceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryResourceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("type") UdfType type){ @RequestParam("type") UdfType type) {
try{
logger.info("query datasource list, user:{}, type:{}", loginUser.getUserName(), type); logger.info("query datasource list, user:{}, type:{}", loginUser.getUserName(), type);
Map<String, Object> result = udfFuncService.queryResourceList(loginUser,type.ordinal()); Map<String, Object> result = udfFuncService.queryResourceList(loginUser, type.ordinal());
return returnDataList(result); 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());
}
} }
/** /**
@ -686,26 +613,21 @@ public class ResourcesController extends BaseController{
* @param name name * @param name name
* @return true if the name can user, otherwise return false * @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({ @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") @GetMapping(value = "/udf-func/verify-name")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(VERIFY_UDF_FUNCTION_NAME_ERROR)
public Result verifyUdfFuncName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, 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: {}", logger.info("login user {}, verfiy udf function name: {}",
loginUser.getUserName(),name); loginUser.getUserName(), name);
try{
return udfFuncService.verifyUdfFuncByName(name); 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());
}
} }
/** /**
@ -715,23 +637,18 @@ public class ResourcesController extends BaseController{
* @param udfFuncId udf function id * @param udfFuncId udf function id
* @return delete result code * @return delete result code
*/ */
@ApiOperation(value = "deleteUdfFunc", notes= "DELETE_UDF_FUNCTION_NOTES") @ApiOperation(value = "deleteUdfFunc", notes = "DELETE_UDF_FUNCTION_NOTES")
@ApiImplicitParams({ @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") @GetMapping(value = "/udf-func/delete")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_UDF_FUNCTION_ERROR)
public Result deleteUdfFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, 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);
logger.info("login user {}, delete udf function id: {}", loginUser.getUserName(),udfFuncId);
return udfFuncService.delete(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());
}
} }
/** /**
@ -741,22 +658,18 @@ public class ResourcesController extends BaseController{
* @param userId user id * @param userId user id
* @return authorized result * @return authorized result
*/ */
@ApiOperation(value = "authorizedFile", notes= "AUTHORIZED_FILE_NOTES") @ApiOperation(value = "authorizedFile", notes = "AUTHORIZED_FILE_NOTES")
@ApiImplicitParams({ @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") @GetMapping(value = "/authed-file")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@ApiException(AUTHORIZED_FILE_RESOURCE_ERROR)
public Result authorizedFile(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result authorizedFile(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("userId") Integer userId) { @RequestParam("userId") Integer userId) {
try{
logger.info("authorized file resource, user: {}, user id:{}", loginUser.getUserName(), userId); logger.info("authorized file resource, user: {}, user id:{}", loginUser.getUserName(), userId);
Map<String, Object> result = resourceService.authorizedFile(loginUser, userId); Map<String, Object> result = resourceService.authorizedFile(loginUser, userId);
return returnDataList(result); 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());
}
} }
@ -767,22 +680,18 @@ public class ResourcesController extends BaseController{
* @param userId user id * @param userId user id
* @return unauthorized result code * @return unauthorized result code
*/ */
@ApiOperation(value = "authorizeResourceTree", notes= "AUTHORIZE_RESOURCE_TREE_NOTES") @ApiOperation(value = "authorizeResourceTree", notes = "AUTHORIZE_RESOURCE_TREE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType ="Int", example = "100") @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100")
}) })
@GetMapping(value = "/authorize-resource-tree") @GetMapping(value = "/authorize-resource-tree")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@ApiException(AUTHORIZE_RESOURCE_TREE)
public Result authorizeResourceTree(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result authorizeResourceTree(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("userId") Integer userId) { @RequestParam("userId") Integer userId) {
try{
logger.info("all resource file, user:{}, user id:{}", loginUser.getUserName(), userId); logger.info("all resource file, user:{}, user id:{}", loginUser.getUserName(), userId);
Map<String, Object> result = resourceService.authorizeResourceTree(loginUser, userId); Map<String, Object> result = resourceService.authorizeResourceTree(loginUser, userId);
return returnDataList(result); 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());
}
} }
@ -793,23 +702,19 @@ public class ResourcesController extends BaseController{
* @param userId user id * @param userId user id
* @return unauthorized result code * @return unauthorized result code
*/ */
@ApiOperation(value = "unauthUDFFunc", notes= "UNAUTHORIZED_UDF_FUNC_NOTES") @ApiOperation(value = "unauthUDFFunc", notes = "UNAUTHORIZED_UDF_FUNC_NOTES")
@ApiImplicitParams({ @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") @GetMapping(value = "/unauth-udf-func")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@ApiException(UNAUTHORIZED_UDF_FUNCTION_ERROR)
public Result unauthUDFFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result unauthUDFFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("userId") Integer userId) { @RequestParam("userId") Integer userId) {
try{
logger.info("unauthorized udf function, login user:{}, unauthorized user id:{}", loginUser.getUserName(), userId); logger.info("unauthorized udf function, login user:{}, unauthorized user id:{}", loginUser.getUserName(), userId);
Map<String, Object> result = resourceService.unauthorizedUDFFunction(loginUser, userId); Map<String, Object> result = resourceService.unauthorizedUDFFunction(loginUser, userId);
return returnDataList(result); 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());
}
} }
@ -820,21 +725,17 @@ public class ResourcesController extends BaseController{
* @param userId user id * @param userId user id
* @return authorized result code * @return authorized result code
*/ */
@ApiOperation(value = "authUDFFunc", notes= "AUTHORIZED_UDF_FUNC_NOTES") @ApiOperation(value = "authUDFFunc", notes = "AUTHORIZED_UDF_FUNC_NOTES")
@ApiImplicitParams({ @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") @GetMapping(value = "/authed-udf-func")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@ApiException(AUTHORIZED_UDF_FUNCTION_ERROR)
public Result authorizedUDFFunction(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result authorizedUDFFunction(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("userId") Integer userId) { @RequestParam("userId") Integer userId) {
try{
logger.info("auth udf function, login user:{}, auth user id:{}", loginUser.getUserName(), userId); logger.info("auth udf function, login user:{}, auth user id:{}", loginUser.getUserName(), userId);
Map<String, Object> result = resourceService.authorizedUDFFunction(loginUser, userId); Map<String, Object> result = resourceService.authorizedUDFFunction(loginUser, userId);
return returnDataList(result); 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());
}
} }
} }

104
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java

@ -17,7 +17,7 @@
package org.apache.dolphinscheduler.api.controller; 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.service.SchedulerService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.enums.FailureStrategy; import org.apache.dolphinscheduler.common.enums.FailureStrategy;
@ -34,6 +34,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import java.io.IOException;
import java.util.Map; import java.util.Map;
import static org.apache.dolphinscheduler.api.enums.Status.*; import static org.apache.dolphinscheduler.api.enums.Status.*;
@ -73,20 +74,21 @@ public class SchedulerController extends BaseController {
* @param workerGroup worker group * @param workerGroup worker group
* @return create result code * @return create result code
*/ */
@ApiOperation(value = "createSchedule", notes= "CREATE_SCHEDULE_NOTES") @ApiOperation(value = "createSchedule", notes = "CREATE_SCHEDULE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "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 = "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 = "warningGroupId", value = "WARNING_GROUP_ID", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", type ="FailureStrategy"), @ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", type = "FailureStrategy"),
@ApiImplicitParam(name = "receivers", value = "RECEIVERS", type ="String"), @ApiImplicitParam(name = "receivers", value = "RECEIVERS", type = "String"),
@ApiImplicitParam(name = "receiversCc", value = "RECEIVERS_CC", type ="String"), @ApiImplicitParam(name = "receiversCc", value = "RECEIVERS_CC", type = "String"),
@ApiImplicitParam(name = "workerGroupId", value = "WORKER_GROUP_ID", dataType = "Int", example = "100"), @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") @PostMapping("/create")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_SCHEDULE_ERROR)
public Result createSchedule(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, public Result createSchedule(@ApiIgnore @RequestAttribute(value = 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(value = "processDefinitionId") Integer processDefinitionId, @RequestParam(value = "processDefinitionId") Integer processDefinitionId,
@ -97,20 +99,15 @@ public class SchedulerController extends BaseController {
@RequestParam(value = "receivers", required = false) String receivers, @RequestParam(value = "receivers", required = false) String receivers,
@RequestParam(value = "receiversCc", required = false) String receiversCc, @RequestParam(value = "receiversCc", required = false) String receiversCc,
@RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, @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: {}," + logger.info("login user {}, project name: {}, process name: {}, create schedule: {}, warning type: {}, warning group id: {}," +
"failure policy: {},receivers : {},receiversCc : {},processInstancePriority : {}, workGroupId:{}", "failure policy: {},receivers : {},receiversCc : {},processInstancePriority : {}, workGroupId:{}",
loginUser.getUserName(), projectName, processDefinitionId, schedule, warningType, warningGroupId, loginUser.getUserName(), projectName, processDefinitionId, schedule, warningType, warningGroupId,
failureStrategy, receivers, receiversCc, processInstancePriority, workerGroup); failureStrategy, receivers, receiversCc, processInstancePriority, workerGroup);
try {
Map<String, Object> result = schedulerService.insertSchedule(loginUser, projectName, processDefinitionId, schedule, Map<String, Object> result = schedulerService.insertSchedule(loginUser, projectName, processDefinitionId, schedule,
warningType, warningGroupId, failureStrategy, receivers, receiversCc, processInstancePriority, workerGroup); warningType, warningGroupId, failureStrategy, receivers, receiversCc, processInstancePriority, workerGroup);
return returnDataList(result); return returnDataList(result);
} catch (Exception e) {
logger.error(CREATE_SCHEDULE_ERROR.getMsg(), e);
return error(CREATE_SCHEDULE_ERROR.getCode(), CREATE_SCHEDULE_ERROR.getMsg());
}
} }
/** /**
@ -129,19 +126,20 @@ public class SchedulerController extends BaseController {
* @param receiversCc receivers cc * @param receiversCc receivers cc
* @return update result code * @return update result code
*/ */
@ApiOperation(value = "updateSchedule", notes= "UPDATE_SCHEDULE_NOTES") @ApiOperation(value = "updateSchedule", notes = "UPDATE_SCHEDULE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "SCHEDULE_ID", required = true, dataType = "Int", example = "100"), @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 = "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 = "warningGroupId", value = "WARNING_GROUP_ID", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", type ="FailureStrategy"), @ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", type = "FailureStrategy"),
@ApiImplicitParam(name = "receivers", value = "RECEIVERS", type ="String"), @ApiImplicitParam(name = "receivers", value = "RECEIVERS", type = "String"),
@ApiImplicitParam(name = "receiversCc", value = "RECEIVERS_CC", type ="String"), @ApiImplicitParam(name = "receiversCc", value = "RECEIVERS_CC", type = "String"),
@ApiImplicitParam(name = "workerGroupId", value = "WORKER_GROUP_ID", dataType = "Int", example = "100"), @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") @PostMapping("/update")
@ApiException(UPDATE_SCHEDULE_ERROR)
public Result updateSchedule(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, public Result updateSchedule(@ApiIgnore @RequestAttribute(value = 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(value = "id") Integer id, @RequestParam(value = "id") Integer id,
@ -152,21 +150,15 @@ public class SchedulerController extends BaseController {
@RequestParam(value = "receivers", required = false) String receivers, @RequestParam(value = "receivers", required = false) String receivers,
@RequestParam(value = "receiversCc", required = false) String receiversCc, @RequestParam(value = "receiversCc", required = false) String receiversCc,
@RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, @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: {}, " + logger.info("login user {}, project name: {},id: {}, updateProcessInstance schedule: {}, notify type: {}, notify mails: {}, " +
"failure policy: {},receivers : {},receiversCc : {},processInstancePriority : {},workerGroupId:{}", "failure policy: {},receivers : {},receiversCc : {},processInstancePriority : {},workerGroupId:{}",
loginUser.getUserName(), projectName, id, schedule, warningType, warningGroupId, failureStrategy, loginUser.getUserName(), projectName, id, schedule, warningType, warningGroupId, failureStrategy,
receivers, receiversCc, processInstancePriority, workerGroup); receivers, receiversCc, processInstancePriority, workerGroup);
try {
Map<String, Object> result = schedulerService.updateSchedule(loginUser, projectName, id, schedule, Map<String, Object> result = schedulerService.updateSchedule(loginUser, projectName, id, schedule,
warningType, warningGroupId, failureStrategy, receivers, receiversCc, null, processInstancePriority, workerGroup); warningType, warningGroupId, failureStrategy, receivers, receiversCc, null, processInstancePriority, workerGroup);
return returnDataList(result); 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());
}
} }
/** /**
@ -177,24 +169,19 @@ public class SchedulerController extends BaseController {
* @param id scheduler id * @param id scheduler id
* @return publish result code * @return publish result code
*/ */
@ApiOperation(value = "online", notes= "ONLINE_SCHEDULE_NOTES") @ApiOperation(value = "online", notes = "ONLINE_SCHEDULE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "SCHEDULE_ID", required = true, dataType = "Int", example = "100") @ApiImplicitParam(name = "id", value = "SCHEDULE_ID", required = true, dataType = "Int", example = "100")
}) })
@PostMapping("/online") @PostMapping("/online")
@ApiException(PUBLISH_SCHEDULE_ONLINE_ERROR)
public Result online(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, public Result online(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable("projectName") String projectName, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable("projectName") String projectName,
@RequestParam("id") Integer id) { @RequestParam("id") Integer id) {
logger.info("login user {}, schedule setScheduleState, project name: {}, id: {}", logger.info("login user {}, schedule setScheduleState, project name: {}, id: {}",
loginUser.getUserName(), projectName, id); loginUser.getUserName(), projectName, id);
try {
Map<String, Object> result = schedulerService.setScheduleState(loginUser, projectName, id, ReleaseState.ONLINE); Map<String, Object> result = schedulerService.setScheduleState(loginUser, projectName, id, ReleaseState.ONLINE);
return returnDataList(result); 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());
}
} }
/** /**
@ -205,25 +192,20 @@ public class SchedulerController extends BaseController {
* @param id schedule id * @param id schedule id
* @return operation result code * @return operation result code
*/ */
@ApiOperation(value = "offline", notes= "OFFLINE_SCHEDULE_NOTES") @ApiOperation(value = "offline", notes = "OFFLINE_SCHEDULE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "SCHEDULE_ID", required = true, dataType = "Int", example = "100") @ApiImplicitParam(name = "id", value = "SCHEDULE_ID", required = true, dataType = "Int", example = "100")
}) })
@PostMapping("/offline") @PostMapping("/offline")
@ApiException(OFFLINE_SCHEDULE_ERROR)
public Result offline(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, public Result offline(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable("projectName") String projectName, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable("projectName") String projectName,
@RequestParam("id") Integer id) { @RequestParam("id") Integer id) {
logger.info("login user {}, schedule offline, project name: {}, process definition id: {}", logger.info("login user {}, schedule offline, project name: {}, process definition id: {}",
loginUser.getUserName(), projectName, id); loginUser.getUserName(), projectName, id);
try {
Map<String, Object> result = schedulerService.setScheduleState(loginUser, projectName, id, ReleaseState.OFFLINE); Map<String, Object> result = schedulerService.setScheduleState(loginUser, projectName, id, ReleaseState.OFFLINE);
return returnDataList(result); 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());
}
} }
/** /**
@ -237,15 +219,16 @@ public class SchedulerController extends BaseController {
* @param searchVal search value * @param searchVal search value
* @return schedule list page * @return schedule list page
*/ */
@ApiOperation(value = "queryScheduleListPaging", notes= "QUERY_SCHEDULE_LIST_PAGING_NOTES") @ApiOperation(value = "queryScheduleListPaging", notes = "QUERY_SCHEDULE_LIST_PAGING_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true,dataType = "Int", example = "100"), @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"), @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"),
@ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "100"), @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", 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, public Result queryScheduleListPaging(@ApiIgnore @RequestAttribute(value = 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 Integer processDefinitionId, @RequestParam Integer processDefinitionId,
@ -254,15 +237,9 @@ public class SchedulerController extends BaseController {
@RequestParam("pageSize") Integer pageSize) { @RequestParam("pageSize") Integer pageSize) {
logger.info("login user {}, query schedule, project name: {}, process definition id: {}", logger.info("login user {}, query schedule, project name: {}, process definition id: {}",
loginUser.getUserName(), projectName, processDefinitionId); loginUser.getUserName(), projectName, processDefinitionId);
try {
searchVal = ParameterUtils.handleEscapes(searchVal); searchVal = ParameterUtils.handleEscapes(searchVal);
Map<String, Object> result = schedulerService.querySchedule(loginUser, projectName, processDefinitionId, searchVal, pageNo, pageSize); Map<String, Object> result = schedulerService.querySchedule(loginUser, projectName, processDefinitionId, searchVal, pageNo, pageSize);
return returnDataListPaging(result); 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());
}
} }
/** /**
@ -273,26 +250,23 @@ public class SchedulerController extends BaseController {
* @param scheduleId scheule id * @param scheduleId scheule id
* @return delete result code * @return delete result code
*/ */
@ApiOperation(value = "deleteScheduleById", notes= "OFFLINE_SCHEDULE_NOTES") @ApiOperation(value = "deleteScheduleById", notes = "OFFLINE_SCHEDULE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "scheduleId", value = "SCHEDULE_ID", required = true, dataType = "Int", example = "100") @ApiImplicitParam(name = "scheduleId", value = "SCHEDULE_ID", required = true, dataType = "Int", example = "100")
}) })
@GetMapping(value="/delete") @GetMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_SCHEDULE_CRON_BY_ID_ERROR)
public Result deleteScheduleById(@RequestAttribute(value = SESSION_USER) User loginUser, public Result deleteScheduleById(@RequestAttribute(value = SESSION_USER) User loginUser,
@PathVariable String projectName, @PathVariable String projectName,
@RequestParam("scheduleId") Integer scheduleId @RequestParam("scheduleId") Integer scheduleId
){ ) {
try{
logger.info("delete schedule by id, login user:{}, project name:{}, schedule id:{}", logger.info("delete schedule by id, login user:{}, project name:{}, schedule id:{}",
loginUser.getUserName(), projectName, scheduleId); loginUser.getUserName(), projectName, scheduleId);
Map<String, Object> result = schedulerService.deleteScheduleById(loginUser, projectName, scheduleId); Map<String, Object> result = schedulerService.deleteScheduleById(loginUser, projectName, scheduleId);
return returnDataList(result); 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());
}
} }
/** /**
* query schedule list * query schedule list
* *
@ -300,19 +274,15 @@ public class SchedulerController extends BaseController {
* @param projectName project name * @param projectName project name
* @return schedule list * @return schedule list
*/ */
@ApiOperation(value = "queryScheduleList", notes= "QUERY_SCHEDULE_LIST_NOTES") @ApiOperation(value = "queryScheduleList", notes = "QUERY_SCHEDULE_LIST_NOTES")
@PostMapping("/list") @PostMapping("/list")
@ApiException(QUERY_SCHEDULE_LIST_ERROR)
public Result queryScheduleList(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, public Result queryScheduleList(@ApiIgnore @RequestAttribute(value = 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) {
try {
logger.info("login user {}, query schedule list, project name: {}", logger.info("login user {}, query schedule list, project name: {}",
loginUser.getUserName(), projectName); loginUser.getUserName(), projectName);
Map<String, Object> result = schedulerService.queryScheduleList(loginUser, projectName); Map<String, Object> result = schedulerService.queryScheduleList(loginUser, projectName);
return returnDataList(result); 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());
}
} }
/** /**
@ -323,24 +293,20 @@ public class SchedulerController extends BaseController {
* @param schedule schedule expression * @param schedule schedule expression
* @return the next five fire time * @return the next five fire time
*/ */
@ApiOperation(value = "previewSchedule", notes= "PREVIEW_SCHEDULE_NOTES") @ApiOperation(value = "previewSchedule", notes = "PREVIEW_SCHEDULE_NOTES")
@ApiImplicitParams({ @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 * * ? *'}"), @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") @PostMapping("/preview")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@ApiException(PREVIEW_SCHEDULE_ERROR)
public Result previewSchedule(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, public Result previewSchedule(@ApiIgnore @RequestAttribute(value = 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(value = "schedule") String schedule @RequestParam(value = "schedule") String schedule
){ ) {
logger.info("login user {}, project name: {}, preview schedule: {}", logger.info("login user {}, project name: {}, preview schedule: {}",
loginUser.getUserName(), projectName, schedule); loginUser.getUserName(), projectName, schedule);
try {
Map<String, Object> result = schedulerService.previewSchedule(loginUser, projectName, schedule); Map<String, Object> result = schedulerService.previewSchedule(loginUser, projectName, schedule);
return returnDataList(result); return returnDataList(result);
} catch (Exception e) {
logger.error(PREVIEW_SCHEDULE_ERROR.getMsg(), e);
return error(PREVIEW_SCHEDULE_ERROR.getCode(), PREVIEW_SCHEDULE_ERROR.getMsg());
}
} }
} }

33
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java

@ -17,6 +17,7 @@
package org.apache.dolphinscheduler.api.controller; 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.service.TaskInstanceService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
@ -24,7 +25,6 @@ import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
import org.apache.dolphinscheduler.common.utils.ParameterUtils; import org.apache.dolphinscheduler.common.utils.ParameterUtils;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.apache.dolphinscheduler.api.enums.Status;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -34,13 +34,15 @@ import springfox.documentation.annotations.ApiIgnore;
import java.util.Map; import java.util.Map;
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_LIST_PAGING_ERROR;
/** /**
* task instance controller * task instance controller
*/ */
@Api(tags = "TASK_INSTANCE_TAG", position = 11) @Api(tags = "TASK_INSTANCE_TAG", position = 11)
@RestController @RestController
@RequestMapping("/projects/{projectName}/task-instance") @RequestMapping("/projects/{projectName}/task-instance")
public class TaskInstanceController extends BaseController{ public class TaskInstanceController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(TaskInstanceController.class); private static final Logger logger = LoggerFactory.getLogger(TaskInstanceController.class);
@ -64,21 +66,22 @@ public class TaskInstanceController extends BaseController{
* @param pageSize page size * @param pageSize page size
* @return task list page * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID",required = false, dataType = "Int", example = "100"), @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = false, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type ="String"), @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"),
@ApiImplicitParam(name = "taskName", value = "TASK_NAME", type ="String"), @ApiImplicitParam(name = "taskName", value = "TASK_NAME", type = "String"),
@ApiImplicitParam(name = "executorName", value = "EXECUTOR_NAME", type ="String"), @ApiImplicitParam(name = "executorName", value = "EXECUTOR_NAME", type = "String"),
@ApiImplicitParam(name = "stateType", value = "EXECUTION_STATUS", type ="ExecutionStatus"), @ApiImplicitParam(name = "stateType", value = "EXECUTION_STATUS", type = "ExecutionStatus"),
@ApiImplicitParam(name = "host", value = "HOST", type ="String"), @ApiImplicitParam(name = "host", value = "HOST", type = "String"),
@ApiImplicitParam(name = "startDate", value = "START_DATE", type ="String"), @ApiImplicitParam(name = "startDate", value = "START_DATE", type = "String"),
@ApiImplicitParam(name = "endDate", value = "END_DATE", type ="String"), @ApiImplicitParam(name = "endDate", value = "END_DATE", type = "String"),
@ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"), @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"),
@ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20") @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20")
}) })
@GetMapping("/list-paging") @GetMapping("/list-paging")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_TASK_LIST_PAGING_ERROR)
public Result queryTaskListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryTaskListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
@RequestParam(value = "processInstanceId", required = false, defaultValue = "0") Integer processInstanceId, @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 = "startDate", required = false) String startTime,
@RequestParam(value = "endDate", required = false) String endTime, @RequestParam(value = "endDate", required = false) String endTime,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize){ @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:{}", 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); projectName, processInstanceId, searchVal, taskName, executorName, stateType, host, startTime, endTime);
searchVal = ParameterUtils.handleEscapes(searchVal); searchVal = ParameterUtils.handleEscapes(searchVal);
Map<String, Object> result = taskInstanceService.queryTaskListPaging( Map<String, Object> result = taskInstanceService.queryTaskListPaging(
loginUser, projectName, processInstanceId, taskName, executorName, startTime, endTime, searchVal, stateType, host, pageNo, pageSize); loginUser, projectName, processInstanceId, taskName, executorName, startTime, endTime, searchVal, stateType, host, pageNo, pageSize);
return returnDataListPaging(result); 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());
}
} }
} }

28
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskRecordController.java

@ -17,11 +17,11 @@
package org.apache.dolphinscheduler.api.controller; 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.service.TaskRecordService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.api.enums.Status;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -31,13 +31,15 @@ import springfox.documentation.annotations.ApiIgnore;
import java.util.Map; import java.util.Map;
import static org.apache.dolphinscheduler.api.enums.Status.*;
/** /**
* data quality controller * data quality controller
*/ */
@ApiIgnore @ApiIgnore
@RestController @RestController
@RequestMapping("/projects/task-record") @RequestMapping("/projects/task-record")
public class TaskRecordController extends BaseController{ public class TaskRecordController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(TaskRecordController.class); private static final Logger logger = LoggerFactory.getLogger(TaskRecordController.class);
@ -63,6 +65,7 @@ public class TaskRecordController extends BaseController{
*/ */
@GetMapping("/list-paging") @GetMapping("/list-paging")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_TASK_RECORD_LIST_PAGING_ERROR)
public Result queryTaskRecordListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryTaskRecordListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "taskName", required = false) String taskName, @RequestParam(value = "taskName", required = false) String taskName,
@RequestParam(value = "state", required = false) String state, @RequestParam(value = "state", required = false) String state,
@ -73,18 +76,12 @@ public class TaskRecordController extends BaseController{
@RequestParam(value = "endDate", required = false) String endTime, @RequestParam(value = "endDate", required = false) String endTime,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize @RequestParam("pageSize") Integer pageSize
){ ) {
try{
logger.info("query task record list, task name:{}, state :{}, taskDate: {}, start:{}, end:{}", logger.info("query task record list, task name:{}, state :{}, taskDate: {}, start:{}, end:{}",
taskName, state, taskDate, startTime, endTime); taskName, state, taskDate, startTime, endTime);
Map<String, Object> result = taskRecordService.queryTaskRecordListPaging(false, taskName, startTime, taskDate, sourceTable, destTable, endTime,state, pageNo, pageSize); Map<String, Object> result = taskRecordService.queryTaskRecordListPaging(false, taskName, startTime, taskDate, sourceTable, destTable, endTime, state, pageNo, pageSize);
return returnDataListPaging(result); 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());
}
} }
/** /**
@ -104,6 +101,7 @@ public class TaskRecordController extends BaseController{
*/ */
@GetMapping("/history-list-paging") @GetMapping("/history-list-paging")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_TASK_RECORD_LIST_PAGING_ERROR)
public Result queryHistoryTaskRecordListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryHistoryTaskRecordListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "taskName", required = false) String taskName, @RequestParam(value = "taskName", required = false) String taskName,
@RequestParam(value = "state", required = false) String state, @RequestParam(value = "state", required = false) String state,
@ -114,18 +112,12 @@ public class TaskRecordController extends BaseController{
@RequestParam(value = "endDate", required = false) String endTime, @RequestParam(value = "endDate", required = false) String endTime,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize @RequestParam("pageSize") Integer pageSize
){ ) {
try{
logger.info("query hisotry task record list, task name:{}, state :{}, taskDate: {}, start:{}, end:{}", logger.info("query hisotry task record list, task name:{}, state :{}, taskDate: {}, start:{}, end:{}",
taskName, state, taskDate, startTime, endTime); taskName, state, taskDate, startTime, endTime);
Map<String, Object> result = taskRecordService.queryTaskRecordListPaging(true, taskName, startTime, taskDate, sourceTable, destTable, endTime,state, pageNo, pageSize); Map<String, Object> result = taskRecordService.queryTaskRecordListPaging(true, taskName, startTime, taskDate, sourceTable, destTable, endTime, state, pageNo, pageSize);
return returnDataListPaging(result); 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());
}
} }
} }

108
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.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.TenantService; import org.apache.dolphinscheduler.api.service.TenantService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
@ -36,6 +37,8 @@ import springfox.documentation.annotations.ApiIgnore;
import java.util.Map; import java.util.Map;
import static org.apache.dolphinscheduler.api.enums.Status.*;
/** /**
* tenant controller * tenant controller
@ -43,7 +46,7 @@ import java.util.Map;
@Api(tags = "TENANT_TAG", position = 1) @Api(tags = "TENANT_TAG", position = 1)
@RestController @RestController
@RequestMapping("/tenant") @RequestMapping("/tenant")
public class TenantController extends BaseController{ public class TenantController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(TenantController.class); private static final Logger logger = LoggerFactory.getLogger(TenantController.class);
@ -61,31 +64,26 @@ public class TenantController extends BaseController{
* @param description description * @param description description
* @return create result code * @return create result code
*/ */
@ApiOperation(value = "createTenant", notes= "CREATE_TENANT_NOTES") @ApiOperation(value = "createTenant", notes = "CREATE_TENANT_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "tenantCode", value = "TENANT_CODE", required = true, dataType = "String"), @ApiImplicitParam(name = "tenantCode", value = "TENANT_CODE", required = true, dataType = "String"),
@ApiImplicitParam(name = "tenantName", value = "TENANT_NAME", 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 = "queueId", value = "QUEUE_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "description", value = "TENANT_DESC", dataType ="String") @ApiImplicitParam(name = "description", value = "TENANT_DESC", dataType = "String")
}) })
@PostMapping(value = "/create") @PostMapping(value = "/create")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_TENANT_ERROR)
public Result createTenant(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result createTenant(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "tenantCode") String tenantCode, @RequestParam(value = "tenantCode") String tenantCode,
@RequestParam(value = "tenantName") String tenantName, @RequestParam(value = "tenantName") String tenantName,
@RequestParam(value = "queueId") int queueId, @RequestParam(value = "queueId") int queueId,
@RequestParam(value = "description",required = false) String description) { @RequestParam(value = "description", required = false) String description) throws Exception {
logger.info("login user {}, create tenant, tenantCode: {}, tenantName: {}, queueId: {}, desc: {}", logger.info("login user {}, create tenant, tenantCode: {}, tenantName: {}, queueId: {}, desc: {}",
loginUser.getUserName(), tenantCode, tenantName, queueId,description); loginUser.getUserName(), tenantCode, tenantName, queueId, description);
try { Map<String, Object> result = tenantService.createTenant(loginUser, tenantCode, tenantName, queueId, description);
Map<String, Object> result = tenantService.createTenant(loginUser,tenantCode,tenantName,queueId,description);
return returnDataList(result); 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());
}
} }
@ -98,32 +96,28 @@ public class TenantController extends BaseController{
* @param pageSize page size * @param pageSize page size
* @return tenant list page * @return tenant list page
*/ */
@ApiOperation(value = "queryTenantlistPaging", notes= "QUERY_TENANT_LIST_PAGING_NOTES") @ApiOperation(value = "queryTenantlistPaging", notes = "QUERY_TENANT_LIST_PAGING_NOTES")
@ApiImplicitParams({ @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 = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"),
@ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType ="Int",example = "20") @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20")
}) })
@GetMapping(value="/list-paging") @GetMapping(value = "/list-paging")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_TENANT_LIST_PAGING_ERROR)
public Result queryTenantlistPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryTenantlistPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageSize") Integer pageSize){ @RequestParam("pageSize") Integer pageSize) {
logger.info("login user {}, list paging, pageNo: {}, searchVal: {}, pageSize: {}", logger.info("login user {}, list paging, pageNo: {}, searchVal: {}, pageSize: {}",
loginUser.getUserName(),pageNo,searchVal,pageSize); loginUser.getUserName(), pageNo, searchVal, pageSize);
try{
Map<String, Object> result = checkPageParams(pageNo, pageSize); Map<String, Object> result = checkPageParams(pageNo, pageSize);
if(result.get(Constants.STATUS) != Status.SUCCESS){ if (result.get(Constants.STATUS) != Status.SUCCESS) {
return returnDataListPaging(result); return returnDataListPaging(result);
} }
searchVal = ParameterUtils.handleEscapes(searchVal); searchVal = ParameterUtils.handleEscapes(searchVal);
result = tenantService.queryTenantList(loginUser, searchVal, pageNo, pageSize); result = tenantService.queryTenantList(loginUser, searchVal, pageNo, pageSize);
return returnDataListPaging(result); 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());
}
} }
@ -133,22 +127,17 @@ public class TenantController extends BaseController{
* @param loginUser login user * @param loginUser login user
* @return tenant list * @return tenant list
*/ */
@ApiOperation(value = "queryTenantlist", notes= "QUERY_TENANT_LIST_NOTES") @ApiOperation(value = "queryTenantlist", notes = "QUERY_TENANT_LIST_NOTES")
@GetMapping(value="/list") @GetMapping(value = "/list")
@ResponseStatus(HttpStatus.OK) @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()); logger.info("login user {}, query tenant list", loginUser.getUserName());
try{
Map<String, Object> result = tenantService.queryTenantList(loginUser); Map<String, Object> result = tenantService.queryTenantList(loginUser);
return returnDataList(result); 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());
}
} }
/** /**
* udpate tenant * udpate tenant
* *
@ -160,32 +149,28 @@ public class TenantController extends BaseController{
* @param description description * @param description description
* @return update result code * @return update result code
*/ */
@ApiOperation(value = "updateTenant", notes= "UPDATE_TENANT_NOTES") @ApiOperation(value = "updateTenant", notes = "UPDATE_TENANT_NOTES")
@ApiImplicitParams({ @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 = "tenantCode", value = "TENANT_CODE", required = true, dataType = "String"),
@ApiImplicitParam(name = "tenantName", value = "TENANT_NAME", 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 = "queueId", value = "QUEUE_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "description", value = "TENANT_DESC", type ="String") @ApiImplicitParam(name = "description", value = "TENANT_DESC", type = "String")
}) })
@PostMapping(value = "/update") @PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_TENANT_ERROR)
public Result updateTenant(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result updateTenant(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int id, @RequestParam(value = "id") int id,
@RequestParam(value = "tenantCode") String tenantCode, @RequestParam(value = "tenantCode") String tenantCode,
@RequestParam(value = "tenantName") String tenantName, @RequestParam(value = "tenantName") String tenantName,
@RequestParam(value = "queueId") int queueId, @RequestParam(value = "queueId") int queueId,
@RequestParam(value = "description",required = false) String description) { @RequestParam(value = "description", required = false) String description) throws Exception {
logger.info("login user {}, updateProcessInstance tenant, tenantCode: {}, tenantName: {}, queueId: {}, description: {}", logger.info("login user {}, updateProcessInstance tenant, tenantCode: {}, tenantName: {}, queueId: {}, description: {}",
loginUser.getUserName(), tenantCode, tenantName, queueId,description); loginUser.getUserName(), tenantCode, tenantName, queueId, description);
try { Map<String, Object> result = tenantService.updateTenant(loginUser, id, tenantCode, tenantName, queueId, description);
Map<String, Object> result = tenantService.updateTenant(loginUser,id,tenantCode, tenantName, queueId, description);
return returnDataList(result); 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());
}
} }
/** /**
@ -195,23 +180,19 @@ public class TenantController extends BaseController{
* @param id tenant id * @param id tenant id
* @return delete result code * @return delete result code
*/ */
@ApiOperation(value = "deleteTenantById", notes= "DELETE_TENANT_NOTES") @ApiOperation(value = "deleteTenantById", notes = "DELETE_TENANT_NOTES")
@ApiImplicitParams({ @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") @PostMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_TENANT_BY_ID_ERROR)
public Result deleteTenantById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, 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); logger.info("login user {}, delete tenant, tenantId: {},", loginUser.getUserName(), id);
try { Map<String, Object> result = tenantService.deleteTenantById(loginUser, id);
Map<String, Object> result = tenantService.deleteTenantById(loginUser,id);
return returnDataList(result); 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());
}
} }
@ -222,24 +203,19 @@ public class TenantController extends BaseController{
* @param tenantCode tenant code * @param tenantCode tenant code
* @return true if tenant code can user, otherwise return false * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "tenantCode", value = "TENANT_CODE", required = true, dataType = "String") @ApiImplicitParam(name = "tenantCode", value = "TENANT_CODE", required = true, dataType = "String")
}) })
@GetMapping(value = "/verify-tenant-code") @GetMapping(value = "/verify-tenant-code")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(VERIFY_TENANT_CODE_ERROR)
public Result verifyTenantCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, 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: {}", logger.info("login user {}, verfiy tenant code: {}",
loginUser.getUserName(),tenantCode); loginUser.getUserName(), tenantCode);
return tenantService.verifyTenantCode(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());
}
} }

209
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.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.UsersService; import org.apache.dolphinscheduler.api.service.UsersService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
@ -36,14 +37,16 @@ import springfox.documentation.annotations.ApiIgnore;
import java.util.Map; import java.util.Map;
import static org.apache.dolphinscheduler.api.enums.Status.*;
/** /**
* user controller * user controller
*/ */
@Api(tags = "USERS_TAG" , position = 14) @Api(tags = "USERS_TAG", position = 14)
@RestController @RestController
@RequestMapping("/users") @RequestMapping("/users")
public class UsersController extends BaseController{ public class UsersController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(UsersController.class); private static final Logger logger = LoggerFactory.getLogger(UsersController.class);
@ -62,10 +65,10 @@ public class UsersController extends BaseController{
* @param queue queue * @param queue queue
* @return create result code * @return create result code
*/ */
@ApiOperation(value = "createUser", notes= "CREATE_USER_NOTES") @ApiOperation(value = "createUser", notes = "CREATE_USER_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "userName", value = "USER_NAME",type = "String"), @ApiImplicitParam(name = "userName", value = "USER_NAME", type = "String"),
@ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", type ="String"), @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", type = "String"),
@ApiImplicitParam(name = "tenantId", value = "TENANT_ID", dataType = "Int", example = "100"), @ApiImplicitParam(name = "tenantId", value = "TENANT_ID", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "queue", value = "QUEUE", dataType = "Int", example = "100"), @ApiImplicitParam(name = "queue", value = "QUEUE", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "email", value = "EMAIL", dataType = "Int", example = "100"), @ApiImplicitParam(name = "email", value = "EMAIL", dataType = "Int", example = "100"),
@ -73,23 +76,19 @@ public class UsersController extends BaseController{
}) })
@PostMapping(value = "/create") @PostMapping(value = "/create")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_USER_ERROR)
public Result createUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result createUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "userName") String userName, @RequestParam(value = "userName") String userName,
@RequestParam(value = "userPassword") String userPassword, @RequestParam(value = "userPassword") String userPassword,
@RequestParam(value = "tenantId") int tenantId, @RequestParam(value = "tenantId") int tenantId,
@RequestParam(value = "queue",required = false,defaultValue = "") String queue, @RequestParam(value = "queue", required = false, defaultValue = "") String queue,
@RequestParam(value = "email") String email, @RequestParam(value = "email") String email,
@RequestParam(value = "phone", required = false) String phone) { @RequestParam(value = "phone", required = false) String phone) throws Exception {
logger.info("login user {}, create user, userName: {}, email: {}, tenantId: {}, userPassword: {}, phone: {}, user queue: {}", 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<String, Object> result = usersService.createUser(loginUser, userName, userPassword, email, tenantId, phone, queue);
Map<String, Object> result = usersService.createUser(loginUser, userName, userPassword,email,tenantId, phone,queue);
return returnDataList(result); 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());
}
} }
/** /**
@ -101,32 +100,28 @@ public class UsersController extends BaseController{
* @param pageSize page size * @param pageSize page size
* @return user list page * @return user list page
*/ */
@ApiOperation(value = "queryUserList", notes= "QUERY_USER_LIST_NOTES") @ApiOperation(value = "queryUserList", notes = "QUERY_USER_LIST_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "pageNo", value = "PAGE_NO",dataType = "Int", example = "100"), @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", type ="String"), @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", type = "String"),
@ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type ="String") @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String")
}) })
@GetMapping(value="/list-paging") @GetMapping(value = "/list-paging")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_USER_LIST_PAGING_ERROR)
public Result queryUserList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryUserList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageSize") Integer pageSize){ @RequestParam("pageSize") Integer pageSize) {
logger.info("login user {}, list user paging, pageNo: {}, searchVal: {}, pageSize: {}", logger.info("login user {}, list user paging, pageNo: {}, searchVal: {}, pageSize: {}",
loginUser.getUserName(),pageNo,searchVal,pageSize); loginUser.getUserName(), pageNo, searchVal, pageSize);
try{
Map<String, Object> result = checkPageParams(pageNo, pageSize); Map<String, Object> result = checkPageParams(pageNo, pageSize);
if(result.get(Constants.STATUS) != Status.SUCCESS){ if (result.get(Constants.STATUS) != Status.SUCCESS) {
return returnDataListPaging(result); return returnDataListPaging(result);
} }
searchVal = ParameterUtils.handleEscapes(searchVal); searchVal = ParameterUtils.handleEscapes(searchVal);
result = usersService.queryUserList(loginUser, searchVal, pageNo, pageSize); result = usersService.queryUserList(loginUser, searchVal, pageNo, pageSize);
return returnDataListPaging(result); 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());
}
} }
@ -143,11 +138,11 @@ public class UsersController extends BaseController{
* @param queue queue * @param queue queue
* @return update result code * @return update result code
*/ */
@ApiOperation(value = "updateUser", notes= "UPDATE_USER_NOTES") @ApiOperation(value = "updateUser", notes = "UPDATE_USER_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "USER_ID",dataType = "Int", example = "100"), @ApiImplicitParam(name = "id", value = "USER_ID", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "userName", value = "USER_NAME",type = "String"), @ApiImplicitParam(name = "userName", value = "USER_NAME", type = "String"),
@ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", type ="String"), @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", type = "String"),
@ApiImplicitParam(name = "tenantId", value = "TENANT_ID", dataType = "Int", example = "100"), @ApiImplicitParam(name = "tenantId", value = "TENANT_ID", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "queue", value = "QUEUE", dataType = "Int", example = "100"), @ApiImplicitParam(name = "queue", value = "QUEUE", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "email", value = "EMAIL", dataType = "Int", example = "100"), @ApiImplicitParam(name = "email", value = "EMAIL", dataType = "Int", example = "100"),
@ -155,47 +150,40 @@ public class UsersController extends BaseController{
}) })
@PostMapping(value = "/update") @PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_USER_ERROR)
public Result updateUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result updateUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int id, @RequestParam(value = "id") int id,
@RequestParam(value = "userName") String userName, @RequestParam(value = "userName") String userName,
@RequestParam(value = "userPassword") String userPassword, @RequestParam(value = "userPassword") String userPassword,
@RequestParam(value = "queue",required = false,defaultValue = "") String queue, @RequestParam(value = "queue", required = false, defaultValue = "") String queue,
@RequestParam(value = "email") String email, @RequestParam(value = "email") String email,
@RequestParam(value = "tenantId") int tenantId, @RequestParam(value = "tenantId") int tenantId,
@RequestParam(value = "phone", required = false) String phone) { @RequestParam(value = "phone", required = false) String phone) throws Exception {
logger.info("login user {}, updateProcessInstance user, userName: {}, email: {}, tenantId: {}, userPassword: {}, phone: {}, user queue: {}", logger.info("login user {}, updateProcessInstance 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<String, Object> result = usersService.updateUser(id, userName, userPassword, email, tenantId, phone, queue); Map<String, Object> result = usersService.updateUser(id, userName, userPassword, email, tenantId, phone, queue);
return returnDataList(result); 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());
}
} }
/** /**
* delete user by id * delete user by id
*
* @param loginUser login user * @param loginUser login user
* @param id user id * @param id user id
* @return delete result code * @return delete result code
*/ */
@ApiOperation(value = "delUserById", notes= "DELETE_USER_BY_ID_NOTES") @ApiOperation(value = "delUserById", notes = "DELETE_USER_BY_ID_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "USER_ID",dataType = "Int", example = "100") @ApiImplicitParam(name = "id", value = "USER_ID", dataType = "Int", example = "100")
}) })
@PostMapping(value = "/delete") @PostMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_USER_BY_ID_ERROR)
public Result delUserById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, 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); logger.info("login user {}, delete user, userId: {},", loginUser.getUserName(), id);
try {
Map<String, Object> result = usersService.deleteUserById(loginUser, id); Map<String, Object> result = usersService.deleteUserById(loginUser, id);
return returnDataList(result); 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());
}
} }
/** /**
@ -206,24 +194,20 @@ public class UsersController extends BaseController{
* @param projectIds project id array * @param projectIds project id array
* @return grant result code * @return grant result code
*/ */
@ApiOperation(value = "grantProject", notes= "GRANT_PROJECT_NOTES") @ApiOperation(value = "grantProject", notes = "GRANT_PROJECT_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "USER_ID",dataType = "Int", example = "100"), @ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "projectIds", value = "PROJECT_IDS",type = "String") @ApiImplicitParam(name = "projectIds", value = "PROJECT_IDS", type = "String")
}) })
@PostMapping(value = "/grant-project") @PostMapping(value = "/grant-project")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(GRANT_PROJECT_ERROR)
public Result grantProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result grantProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "userId") int userId, @RequestParam(value = "userId") int userId,
@RequestParam(value = "projectIds") String projectIds) { @RequestParam(value = "projectIds") String projectIds) {
logger.info("login user {}, grant project, userId: {},projectIds : {}", loginUser.getUserName(), userId,projectIds); logger.info("login user {}, grant project, userId: {},projectIds : {}", loginUser.getUserName(), userId, projectIds);
try {
Map<String, Object> result = usersService.grantProject(loginUser, userId, projectIds); Map<String, Object> result = usersService.grantProject(loginUser, userId, projectIds);
return returnDataList(result); 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());
}
} }
/** /**
@ -234,24 +218,20 @@ public class UsersController extends BaseController{
* @param resourceIds resource id array * @param resourceIds resource id array
* @return grant result code * @return grant result code
*/ */
@ApiOperation(value = "grantResource", notes= "GRANT_RESOURCE_NOTES") @ApiOperation(value = "grantResource", notes = "GRANT_RESOURCE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "USER_ID",dataType = "Int", example = "100"), @ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "resourceIds", value = "RESOURCE_IDS",type = "String") @ApiImplicitParam(name = "resourceIds", value = "RESOURCE_IDS", type = "String")
}) })
@PostMapping(value = "/grant-file") @PostMapping(value = "/grant-file")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(GRANT_RESOURCE_ERROR)
public Result grantResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result grantResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "userId") int userId, @RequestParam(value = "userId") int userId,
@RequestParam(value = "resourceIds") String resourceIds) { @RequestParam(value = "resourceIds") String resourceIds) {
logger.info("login user {}, grant project, userId: {},resourceIds : {}", loginUser.getUserName(), userId,resourceIds); logger.info("login user {}, grant project, userId: {},resourceIds : {}", loginUser.getUserName(), userId, resourceIds);
try {
Map<String, Object> result = usersService.grantResources(loginUser, userId, resourceIds); Map<String, Object> result = usersService.grantResources(loginUser, userId, resourceIds);
return returnDataList(result); 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());
}
} }
@ -263,28 +243,23 @@ public class UsersController extends BaseController{
* @param udfIds udf id array * @param udfIds udf id array
* @return grant result code * @return grant result code
*/ */
@ApiOperation(value = "grantUDFFunc", notes= "GRANT_UDF_FUNC_NOTES") @ApiOperation(value = "grantUDFFunc", notes = "GRANT_UDF_FUNC_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "USER_ID",dataType = "Int", example = "100"), @ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "udfIds", value = "UDF_IDS",type = "String") @ApiImplicitParam(name = "udfIds", value = "UDF_IDS", type = "String")
}) })
@PostMapping(value = "/grant-udf-func") @PostMapping(value = "/grant-udf-func")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(GRANT_UDF_FUNCTION_ERROR)
public Result grantUDFFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result grantUDFFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "userId") int userId, @RequestParam(value = "userId") int userId,
@RequestParam(value = "udfIds") String udfIds) { @RequestParam(value = "udfIds") String udfIds) {
logger.info("login user {}, grant project, userId: {},resourceIds : {}", loginUser.getUserName(), userId,udfIds); logger.info("login user {}, grant project, userId: {},resourceIds : {}", loginUser.getUserName(), userId, udfIds);
try {
Map<String, Object> result = usersService.grantUDFFunction(loginUser, userId, udfIds); Map<String, Object> result = usersService.grantUDFFunction(loginUser, userId, udfIds);
return returnDataList(result); 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());
}
} }
/** /**
* grant datasource * grant datasource
* *
@ -293,24 +268,20 @@ public class UsersController extends BaseController{
* @param datasourceIds data source id array * @param datasourceIds data source id array
* @return grant result code * @return grant result code
*/ */
@ApiOperation(value = "grantDataSource", notes= "GRANT_DATASOURCE_NOTES") @ApiOperation(value = "grantDataSource", notes = "GRANT_DATASOURCE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "USER_ID",dataType = "Int", example = "100"), @ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "datasourceIds", value = "DATASOURCE_IDS",type = "String") @ApiImplicitParam(name = "datasourceIds", value = "DATASOURCE_IDS", type = "String")
}) })
@PostMapping(value = "/grant-datasource") @PostMapping(value = "/grant-datasource")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(GRANT_DATASOURCE_ERROR)
public Result grantDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result grantDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "userId") int userId, @RequestParam(value = "userId") int userId,
@RequestParam(value = "datasourceIds") String datasourceIds) { @RequestParam(value = "datasourceIds") String datasourceIds) {
logger.info("login user {}, grant project, userId: {},projectIds : {}", loginUser.getUserName(),userId,datasourceIds); logger.info("login user {}, grant project, userId: {},projectIds : {}", loginUser.getUserName(), userId, datasourceIds);
try {
Map<String, Object> result = usersService.grantDataSource(loginUser, userId, datasourceIds); Map<String, Object> result = usersService.grantDataSource(loginUser, userId, datasourceIds);
return returnDataList(result); 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());
}
} }
@ -320,18 +291,14 @@ public class UsersController extends BaseController{
* @param loginUser login user * @param loginUser login user
* @return user info * @return user info
*/ */
@ApiOperation(value = "getUserInfo", notes= "GET_USER_INFO_NOTES") @ApiOperation(value = "getUserInfo", notes = "GET_USER_INFO_NOTES")
@GetMapping(value="/get-user-info") @GetMapping(value = "/get-user-info")
@ResponseStatus(HttpStatus.OK) @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()); logger.info("login user {},get user info", loginUser.getUserName());
try{
Map<String, Object> result = usersService.getUserInfo(loginUser); Map<String, Object> result = usersService.getUserInfo(loginUser);
return returnDataList(result); 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());
}
} }
/** /**
@ -340,18 +307,14 @@ public class UsersController extends BaseController{
* @param loginUser login user * @param loginUser login user
* @return user list * @return user list
*/ */
@ApiOperation(value = "listUser", notes= "LIST_USER_NOTES") @ApiOperation(value = "listUser", notes = "LIST_USER_NOTES")
@GetMapping(value="/list") @GetMapping(value = "/list")
@ResponseStatus(HttpStatus.OK) @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()); logger.info("login user {}, user list", loginUser.getUserName());
try{
Map<String, Object> result = usersService.queryAllGeneralUsers(loginUser); Map<String, Object> result = usersService.queryAllGeneralUsers(loginUser);
return returnDataList(result); 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());
}
} }
@ -361,17 +324,13 @@ public class UsersController extends BaseController{
* @param loginUser login user * @param loginUser login user
* @return user list * @return user list
*/ */
@GetMapping(value="/list-all") @GetMapping(value = "/list-all")
@ResponseStatus(HttpStatus.OK) @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()); logger.info("login user {}, user list", loginUser.getUserName());
try{
Map<String, Object> result = usersService.queryUserList(loginUser); Map<String, Object> result = usersService.queryUserList(loginUser);
return returnDataList(result); 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());
}
} }
@ -382,24 +341,19 @@ public class UsersController extends BaseController{
* @param userName user name * @param userName user name
* @return true if user name not exists, otherwise return false * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "userName", value = "USER_NAME",type = "String") @ApiImplicitParam(name = "userName", value = "USER_NAME", type = "String")
}) })
@GetMapping(value = "/verify-user-name") @GetMapping(value = "/verify-user-name")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(VERIFY_USERNAME_ERROR)
public Result verifyUserName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, 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: {}", logger.info("login user {}, verfiy user name: {}",
loginUser.getUserName(),userName); loginUser.getUserName(), userName);
return usersService.verifyUserName(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());
}
} }
@ -410,23 +364,19 @@ public class UsersController extends BaseController{
* @param alertgroupId alert group id * @param alertgroupId alert group id
* @return unauthorize result code * @return unauthorize result code
*/ */
@ApiOperation(value = "unauthorizedUser", notes= "UNAUTHORIZED_USER_NOTES") @ApiOperation(value = "unauthorizedUser", notes = "UNAUTHORIZED_USER_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "alertgroupId", value = "ALERT_GROUP_ID",type = "String") @ApiImplicitParam(name = "alertgroupId", value = "ALERT_GROUP_ID", type = "String")
}) })
@GetMapping(value = "/unauth-user") @GetMapping(value = "/unauth-user")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(UNAUTHORIZED_USER_ERROR)
public Result unauthorizedUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result unauthorizedUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("alertgroupId") Integer alertgroupId) { @RequestParam("alertgroupId") Integer alertgroupId) {
try{
logger.info("unauthorized user, login user:{}, alert group id:{}", logger.info("unauthorized user, login user:{}, alert group id:{}",
loginUser.getUserName(), alertgroupId); loginUser.getUserName(), alertgroupId);
Map<String, Object> result = usersService.unauthorizedUser(loginUser, alertgroupId); Map<String, Object> result = usersService.unauthorizedUser(loginUser, alertgroupId);
return returnDataList(result); 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());
}
} }
@ -437,21 +387,22 @@ public class UsersController extends BaseController{
* @param alertgroupId alert group id * @param alertgroupId alert group id
* @return authorized result code * @return authorized result code
*/ */
@ApiOperation(value = "authorizedUser", notes= "AUTHORIZED_USER_NOTES") @ApiOperation(value = "authorizedUser", notes = "AUTHORIZED_USER_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "alertgroupId", value = "ALERT_GROUP_ID",type = "String") @ApiImplicitParam(name = "alertgroupId", value = "ALERT_GROUP_ID", type = "String")
}) })
@GetMapping(value = "/authed-user") @GetMapping(value = "/authed-user")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(AUTHORIZED_USER_ERROR)
public Result authorizedUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result authorizedUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("alertgroupId") Integer alertgroupId) { @RequestParam("alertgroupId") Integer alertgroupId) {
try{ try {
logger.info("authorized user , login user:{}, alert group id:{}", logger.info("authorized user , login user:{}, alert group id:{}",
loginUser.getUserName(), alertgroupId); loginUser.getUserName(), alertgroupId);
Map<String, Object> result = usersService.authorizedUser(loginUser, alertgroupId); Map<String, Object> result = usersService.authorizedUser(loginUser, alertgroupId);
return returnDataList(result); return returnDataList(result);
}catch (Exception e){ } catch (Exception e) {
logger.error(Status.AUTHORIZED_USER_ERROR.getMsg(),e); logger.error(Status.AUTHORIZED_USER_ERROR.getMsg(), e);
return error(Status.AUTHORIZED_USER_ERROR.getCode(), Status.AUTHORIZED_USER_ERROR.getMsg()); return error(Status.AUTHORIZED_USER_ERROR.getCode(), Status.AUTHORIZED_USER_ERROR.getMsg());
} }
} }

60
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java

@ -17,7 +17,7 @@
package org.apache.dolphinscheduler.api.controller; 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.service.WorkerGroupService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
@ -27,7 +27,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.dolphinscheduler.service.zk.ZookeeperCachedOperator;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -35,16 +34,17 @@ import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
import java.util.Map; import java.util.Map;
import static org.apache.dolphinscheduler.api.enums.Status.*;
/** /**
* worker group controller * worker group controller
*/ */
@Api(tags = "WORKER_GROUP_TAG", position = 1) @Api(tags = "WORKER_GROUP_TAG", position = 1)
@RestController @RestController
@RequestMapping("/worker-group") @RequestMapping("/worker-group")
public class WorkerGroupController extends BaseController{ public class WorkerGroupController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(WorkerGroupController.class); private static final Logger logger = LoggerFactory.getLogger(WorkerGroupController.class);
@ -61,14 +61,15 @@ public class WorkerGroupController extends BaseController{
* @param ipList ip list * @param ipList ip list
* @return create or update result code * @return create or update result code
*/ */
@ApiOperation(value = "saveWorkerGroup", notes= "CREATE_WORKER_GROUP_NOTES") @ApiOperation(value = "saveWorkerGroup", notes = "CREATE_WORKER_GROUP_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "WORKER_GROUP_ID", dataType = "Int", example = "10", defaultValue = "0"), @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 = "name", value = "WORKER_GROUP_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "ipList", value = "WORKER_IP_LIST", required = true, dataType ="String") @ApiImplicitParam(name = "ipList", value = "WORKER_IP_LIST", required = true, dataType = "String")
}) })
@PostMapping(value = "/save") @PostMapping(value = "/save")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(SAVE_ERROR)
public Result saveWorkerGroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result saveWorkerGroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id", required = false, defaultValue = "0") int id, @RequestParam(value = "id", required = false, defaultValue = "0") int id,
@RequestParam(value = "name") String name, @RequestParam(value = "name") String name,
@ -77,13 +78,8 @@ public class WorkerGroupController extends BaseController{
logger.info("save worker group: login user {}, id:{}, name: {}, ipList: {} ", logger.info("save worker group: login user {}, id:{}, name: {}, ipList: {} ",
loginUser.getUserName(), id, name, ipList); loginUser.getUserName(), id, name, ipList);
try { Map<String, Object> result = workerGroupService.saveWorkerGroup(loginUser, id, name, ipList);
Map<String, Object> result = workerGroupService.saveWorkerGroup(loginUser,id, name, ipList);
return returnDataList(result); return returnDataList(result);
}catch (Exception e){
logger.error(Status.SAVE_ERROR.getMsg(),e);
return error(Status.SAVE_ERROR.getCode(), Status.SAVE_ERROR.getMsg());
}
} }
/** /**
@ -95,30 +91,26 @@ public class WorkerGroupController extends BaseController{
* @param pageSize page size * @param pageSize page size
* @return worker group list page * @return worker group list page
*/ */
@ApiOperation(value = "queryAllWorkerGroupsPaging", notes= "QUERY_WORKER_GROUP_PAGING_NOTES") @ApiOperation(value = "queryAllWorkerGroupsPaging", notes = "QUERY_WORKER_GROUP_PAGING_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "WORKER_GROUP_ID", dataType = "Int", example = "10", defaultValue = "0"), @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 = "name", value = "WORKER_GROUP_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "ipList", value = "WORKER_IP_LIST", required = true, dataType ="String") @ApiImplicitParam(name = "ipList", value = "WORKER_IP_LIST", required = true, dataType = "String")
}) })
@GetMapping(value = "/list-paging") @GetMapping(value = "/list-paging")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_WORKER_GROUP_FAIL)
public Result queryAllWorkerGroupsPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryAllWorkerGroupsPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageSize") Integer pageSize @RequestParam("pageSize") Integer pageSize
) { ) {
logger.info("query all worker group paging: login user {}, pageNo:{}, pageSize:{}, searchVal:{}", logger.info("query all worker group paging: login user {}, pageNo:{}, pageSize:{}, searchVal:{}",
loginUser.getUserName() , pageNo, pageSize, searchVal); loginUser.getUserName(), pageNo, pageSize, searchVal);
try {
searchVal = ParameterUtils.handleEscapes(searchVal); searchVal = ParameterUtils.handleEscapes(searchVal);
Map<String, Object> result = workerGroupService.queryAllGroupPaging(loginUser,pageNo, pageSize, searchVal); Map<String, Object> result = workerGroupService.queryAllGroupPaging(loginUser, pageNo, pageSize, searchVal);
return returnDataListPaging(result); 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());
}
} }
/** /**
@ -127,49 +119,41 @@ public class WorkerGroupController extends BaseController{
* @param loginUser login user * @param loginUser login user
* @return all worker group list * @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") @GetMapping(value = "/all-groups")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_WORKER_GROUP_FAIL)
public Result queryAllWorkerGroups(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser public Result queryAllWorkerGroups(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser
) { ) {
logger.info("query all worker group: login user {}", logger.info("query all worker group: login user {}",
loginUser.getUserName() ); loginUser.getUserName());
try {
Map<String, Object> result = workerGroupService.queryAllGroup(); Map<String, Object> result = workerGroupService.queryAllGroup();
return returnDataList(result); 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());
}
} }
/** /**
* delete worker group by id * delete worker group by id
*
* @param loginUser login user * @param loginUser login user
* @param id group id * @param id group id
* @return delete result code * @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({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "WORKER_GROUP_ID", required = true, dataType = "Int", example = "10"), @ApiImplicitParam(name = "id", value = "WORKER_GROUP_ID", required = true, dataType = "Int", example = "10"),
}) })
@GetMapping(value = "/delete-by-id") @GetMapping(value = "/delete-by-id")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_WORKER_GROUP_FAIL)
public Result deleteById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, 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:{} ", logger.info("delete worker group: login user {}, id:{} ",
loginUser.getUserName() , id); loginUser.getUserName(), id);
try {
Map<String, Object> result = workerGroupService.deleteWorkerGroupById(id); Map<String, Object> result = workerGroupService.deleteWorkerGroupById(id);
return returnDataList(result); 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());
}
} }
} }

3
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandler.java

@ -36,12 +36,13 @@ public class ApiExceptionHandler {
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
public Result exceptionHandler(Exception e, HandlerMethod hm) { public Result exceptionHandler(Exception e, HandlerMethod hm) {
logger.error(e.getMessage(), e);
ApiException ce = hm.getMethodAnnotation(ApiException.class); ApiException ce = hm.getMethodAnnotation(ApiException.class);
if (ce == null) { if (ce == null) {
logger.error(e.getMessage(), e);
return Result.errorWithArgs(Status.INTERNAL_SERVER_ERROR_ARGS, e.getMessage()); return Result.errorWithArgs(Status.INTERNAL_SERVER_ERROR_ARGS, e.getMessage());
} }
Status st = ce.value(); Status st = ce.value();
logger.error(st.getMsg(), e);
return Result.error(st); return Result.error(st);
} }

12
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandlerTest.java

@ -17,6 +17,7 @@
package org.apache.dolphinscheduler.api.exceptions; package org.apache.dolphinscheduler.api.exceptions;
import org.apache.dolphinscheduler.api.controller.AccessTokenController; 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.enums.Status;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
@ -24,6 +25,7 @@ import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.HandlerMethod;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -39,4 +41,14 @@ public class ApiExceptionHandlerTest {
Result result = handler.exceptionHandler(new RuntimeException("test exception"), hm); Result result = handler.exceptionHandler(new RuntimeException("test exception"), hm);
Assert.assertEquals(Status.CREATE_ACCESS_TOKEN_ERROR.getCode(),result.getCode().intValue()); 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());
}
} }

14
dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/instance/pages/gantt/_source/gantt.js

@ -24,7 +24,7 @@ let Gantt = function () {
this.tasks = [] this.tasks = []
this.width = null this.width = null
this.height = null this.height = null
this.tasksName = [] this.taskNames = []
this.tickFormat = `%H:%M:%S` this.tickFormat = `%H:%M:%S`
this.margin = { this.margin = {
top: 10, top: 10,
@ -39,8 +39,12 @@ let Gantt = function () {
Gantt.prototype.init = function ({ el, tasks }) { Gantt.prototype.init = function ({ el, tasks }) {
this.el = el this.el = el
this.tasks = tasks this.tasks = tasks
this.tasksName = _.map(_.cloneDeep(tasks), v => v.taskName) this.taskNames = _.map(_.cloneDeep(tasks), v => v.taskName)
this.height = parseInt(this.tasksName.length * 30) this.taskNames = this.taskNames.reduce(function (prev, cur) {
prev.indexOf(cur) === -1 && prev.push(cur);
return prev;
},[])
this.height = parseInt(this.taskNames.length * 30)
this.width = $(this.el).width() - this.margin.right - this.margin.left - 5 this.width = $(this.el).width() - this.margin.right - this.margin.left - 5
this.x = d3.time.scale() this.x = d3.time.scale()
@ -49,7 +53,7 @@ Gantt.prototype.init = function ({ el, tasks }) {
.clamp(true) .clamp(true)
this.y = d3.scale.ordinal() this.y = d3.scale.ordinal()
.domain(this.tasksName) .domain(this.taskNames)
.rangeRoundBands([ 0, this.height - this.margin.top - this.margin.bottom ], 0.1) .rangeRoundBands([ 0, this.height - this.margin.top - this.margin.bottom ], 0.1)
this.xAxis = d3.svg.axis() this.xAxis = d3.svg.axis()
@ -98,7 +102,7 @@ Gantt.prototype.initializeXAxis = function () {
.clamp(true) .clamp(true)
this.y = d3.scale.ordinal() this.y = d3.scale.ordinal()
.domain(this.tasksName) .domain(this.taskNames)
.rangeRoundBands([ 0, this.height - this.margin.top - this.margin.bottom ], 0.1) .rangeRoundBands([ 0, this.height - this.margin.top - this.margin.bottom ], 0.1)
this.xAxis = d3.svg.axis() this.xAxis = d3.svg.axis()

Loading…
Cancel
Save