Remove API Result in Service (#15181)
This commit is contained in:
parent
90250998c4
commit
9be81be328
|
|
@ -26,12 +26,14 @@ import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_ACCESS_TOKEN_E
|
|||
|
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
||||
import org.apache.dolphinscheduler.api.service.AccessTokenService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.dao.entity.AccessToken;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
|
@ -81,12 +83,13 @@ public class AccessTokenController extends BaseController {
|
|||
@PostMapping()
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ApiException(CREATE_ACCESS_TOKEN_ERROR)
|
||||
public Result createToken(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "userId") int userId,
|
||||
@RequestParam(value = "expireTime") String expireTime,
|
||||
@RequestParam(value = "token", required = false) String token) {
|
||||
public Result<AccessToken> createToken(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "userId") int userId,
|
||||
@RequestParam(value = "expireTime") String expireTime,
|
||||
@RequestParam(value = "token", required = false) String token) {
|
||||
|
||||
return accessTokenService.createToken(loginUser, userId, expireTime, token);
|
||||
AccessToken accessToken = accessTokenService.createToken(loginUser, userId, expireTime, token);
|
||||
return Result.success(accessToken);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -101,11 +104,11 @@ public class AccessTokenController extends BaseController {
|
|||
@PostMapping(value = "/generate")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ApiException(GENERATE_TOKEN_ERROR)
|
||||
public Result generateToken(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "userId") int userId,
|
||||
@RequestParam(value = "expireTime") String expireTime) {
|
||||
Map<String, Object> result = accessTokenService.generateToken(loginUser, userId, expireTime);
|
||||
return returnDataList(result);
|
||||
public Result<String> generateToken(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "userId") int userId,
|
||||
@RequestParam(value = "expireTime") String expireTime) {
|
||||
String token = accessTokenService.generateToken(loginUser, userId, expireTime);
|
||||
return Result.success(token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -126,18 +129,16 @@ public class AccessTokenController extends BaseController {
|
|||
@GetMapping()
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_ACCESSTOKEN_LIST_PAGING_ERROR)
|
||||
public Result queryAccessTokenList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
public Result<PageInfo<AccessToken>> queryAccessTokenList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
result = accessTokenService.queryAccessTokenList(loginUser, searchVal, pageNo, pageSize);
|
||||
return result;
|
||||
PageInfo<AccessToken> accessTokenPageInfo =
|
||||
accessTokenService.queryAccessTokenList(loginUser, searchVal, pageNo, pageSize);
|
||||
return Result.success(accessTokenPageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -154,10 +155,10 @@ public class AccessTokenController extends BaseController {
|
|||
@GetMapping(value = "/user/{userId}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_ACCESSTOKEN_BY_USER_ERROR)
|
||||
public Result queryAccessTokenByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable("userId") Integer userId) {
|
||||
Map<String, Object> result = this.accessTokenService.queryAccessTokenByUser(loginUser, userId);
|
||||
return this.returnDataList(result);
|
||||
public Result<List<AccessToken>> queryAccessTokenByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable("userId") Integer userId) {
|
||||
List<AccessToken> accessTokens = accessTokenService.queryAccessTokenByUser(loginUser, userId);
|
||||
return Result.success(accessTokens);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -171,10 +172,10 @@ public class AccessTokenController extends BaseController {
|
|||
@DeleteMapping(value = "/{id}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(DELETE_ACCESS_TOKEN_ERROR)
|
||||
public Result delAccessTokenById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id) {
|
||||
Map<String, Object> result = accessTokenService.delAccessTokenById(loginUser, id);
|
||||
return returnDataList(result);
|
||||
public Result<Boolean> delAccessTokenById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id) {
|
||||
accessTokenService.deleteAccessTokenById(loginUser, id);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -197,14 +198,14 @@ public class AccessTokenController extends BaseController {
|
|||
@PutMapping(value = "/{id}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(UPDATE_ACCESS_TOKEN_ERROR)
|
||||
public Result updateToken(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id,
|
||||
@RequestParam(value = "userId") int userId,
|
||||
@RequestParam(value = "expireTime") String expireTime,
|
||||
@RequestParam(value = "token", required = false) String token) {
|
||||
public Result<AccessToken> updateToken(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id,
|
||||
@RequestParam(value = "userId") int userId,
|
||||
@RequestParam(value = "expireTime") String expireTime,
|
||||
@RequestParam(value = "token", required = false) String token) {
|
||||
|
||||
Map<String, Object> result = accessTokenService.updateToken(loginUser, id, userId, expireTime, token);
|
||||
return returnDataList(result);
|
||||
AccessToken accessToken = accessTokenService.updateToken(loginUser, id, userId, expireTime, token);
|
||||
return Result.success(accessToken);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,12 +27,14 @@ import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_ALERT_GROUP_ER
|
|||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
||||
import org.apache.dolphinscheduler.api.service.AlertGroupService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.dao.entity.AlertGroup;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
|
@ -84,13 +86,12 @@ public class AlertGroupController extends BaseController {
|
|||
@PostMapping()
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ApiException(CREATE_ALERT_GROUP_ERROR)
|
||||
public Result createAlertgroup(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "groupName") String groupName,
|
||||
@RequestParam(value = "description", required = false) String description,
|
||||
@RequestParam(value = "alertInstanceIds") String alertInstanceIds) {
|
||||
Map<String, Object> result =
|
||||
alertGroupService.createAlertgroup(loginUser, groupName, description, alertInstanceIds);
|
||||
return returnDataList(result);
|
||||
public Result<AlertGroup> createAlertGroup(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "groupName") String groupName,
|
||||
@RequestParam(value = "description", required = false) String description,
|
||||
@RequestParam(value = "alertInstanceIds") String alertInstanceIds) {
|
||||
AlertGroup alertgroup = alertGroupService.createAlertGroup(loginUser, groupName, description, alertInstanceIds);
|
||||
return Result.success(alertgroup);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -103,10 +104,10 @@ public class AlertGroupController extends BaseController {
|
|||
@GetMapping(value = "/list")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_ALL_ALERTGROUP_ERROR)
|
||||
public Result list(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
public Result<List<AlertGroup>> list(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
|
||||
Map<String, Object> result = alertGroupService.queryAlertgroup(loginUser);
|
||||
return returnDataList(result);
|
||||
List<AlertGroup> alertGroups = alertGroupService.queryAllAlertGroup(loginUser);
|
||||
return Result.success(alertGroups);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -119,10 +120,10 @@ public class AlertGroupController extends BaseController {
|
|||
@GetMapping(value = "/normal-list")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_ALL_ALERTGROUP_ERROR)
|
||||
public Result normalAlertGroupList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
public Result<List<AlertGroup>> normalAlertGroupList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
|
||||
Map<String, Object> result = alertGroupService.queryNormalAlertgroup(loginUser);
|
||||
return returnDataList(result);
|
||||
List<AlertGroup> alertGroups = alertGroupService.queryNormalAlertGroups(loginUser);
|
||||
return Result.success(alertGroups);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -143,22 +144,21 @@ public class AlertGroupController extends BaseController {
|
|||
@GetMapping()
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(LIST_PAGING_ALERT_GROUP_ERROR)
|
||||
public Result listPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
public Result<PageInfo<AlertGroup>> listPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
return alertGroupService.listPaging(loginUser, searchVal, pageNo, pageSize);
|
||||
PageInfo<AlertGroup> alertGroupPageInfo = alertGroupService.listPaging(loginUser, searchVal, pageNo, pageSize);
|
||||
return Result.success(alertGroupPageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* check alarm group detail by Id
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param id alert group id
|
||||
* @param id alert group id
|
||||
* @return one alert group
|
||||
*/
|
||||
|
||||
|
|
@ -169,11 +169,11 @@ public class AlertGroupController extends BaseController {
|
|||
@PostMapping(value = "/query")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_ALERT_GROUP_ERROR)
|
||||
public Result queryAlertGroupById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("id") Integer id) {
|
||||
public Result<AlertGroup> queryAlertGroupById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("id") Integer id) {
|
||||
|
||||
Map<String, Object> result = alertGroupService.queryAlertGroupById(loginUser, id);
|
||||
return returnDataList(result);
|
||||
AlertGroup alertGroup = alertGroupService.queryAlertGroupById(loginUser, id);
|
||||
return Result.success(alertGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -195,15 +195,14 @@ public class AlertGroupController extends BaseController {
|
|||
@PutMapping(value = "/{id}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(UPDATE_ALERT_GROUP_ERROR)
|
||||
public Result updateAlertgroup(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id,
|
||||
@RequestParam(value = "groupName") String groupName,
|
||||
@RequestParam(value = "description", required = false) String description,
|
||||
@RequestParam(value = "alertInstanceIds") String alertInstanceIds) {
|
||||
|
||||
Map<String, Object> result =
|
||||
alertGroupService.updateAlertgroup(loginUser, id, groupName, description, alertInstanceIds);
|
||||
return returnDataList(result);
|
||||
public Result<AlertGroup> updateAlertGroupById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id,
|
||||
@RequestParam(value = "groupName") String groupName,
|
||||
@RequestParam(value = "description", required = false) String description,
|
||||
@RequestParam(value = "alertInstanceIds") String alertInstanceIds) {
|
||||
AlertGroup alertGroup =
|
||||
alertGroupService.updateAlertGroupById(loginUser, id, groupName, description, alertInstanceIds);
|
||||
return Result.success(alertGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -220,10 +219,10 @@ public class AlertGroupController extends BaseController {
|
|||
@DeleteMapping(value = "/{id}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(DELETE_ALERT_GROUP_ERROR)
|
||||
public Result delAlertgroupById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id) {
|
||||
Map<String, Object> result = alertGroupService.delAlertgroupById(loginUser, id);
|
||||
return returnDataList(result);
|
||||
public Result<Boolean> deleteAlertGroupById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id) {
|
||||
alertGroupService.deleteAlertGroupById(loginUser, id);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -28,14 +28,17 @@ import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_ALERT_PLUGIN_I
|
|||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
||||
import org.apache.dolphinscheduler.api.service.AlertPluginInstanceService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.api.vo.AlertPluginInstanceVO;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.AlertPluginInstanceType;
|
||||
import org.apache.dolphinscheduler.common.enums.WarningType;
|
||||
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
|
@ -88,16 +91,15 @@ public class AlertPluginInstanceController extends BaseController {
|
|||
@PostMapping()
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ApiException(CREATE_ALERT_PLUGIN_INSTANCE_ERROR)
|
||||
public Result createAlertPluginInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "pluginDefineId") int pluginDefineId,
|
||||
@RequestParam(value = "instanceName") String instanceName,
|
||||
@RequestParam(value = "instanceType") AlertPluginInstanceType instanceType,
|
||||
@RequestParam(value = "warningType") WarningType warningType,
|
||||
@RequestParam(value = "pluginInstanceParams") String pluginInstanceParams) {
|
||||
Map<String, Object> result =
|
||||
alertPluginInstanceService.create(loginUser, pluginDefineId, instanceName, instanceType, warningType,
|
||||
pluginInstanceParams);
|
||||
return returnDataList(result);
|
||||
public Result<AlertPluginInstance> createAlertPluginInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "pluginDefineId") int pluginDefineId,
|
||||
@RequestParam(value = "instanceName") String instanceName,
|
||||
@RequestParam(value = "instanceType") AlertPluginInstanceType instanceType,
|
||||
@RequestParam(value = "warningType") WarningType warningType,
|
||||
@RequestParam(value = "pluginInstanceParams") String pluginInstanceParams) {
|
||||
AlertPluginInstance alertPluginInstance = alertPluginInstanceService.create(loginUser, pluginDefineId,
|
||||
instanceName, instanceType, warningType, pluginInstanceParams);
|
||||
return Result.success(alertPluginInstance);
|
||||
}
|
||||
|
||||
@Operation(summary = "testSendAlertPluginInstance", description = "TEST_SEND_ALERT_PLUGIN_INSTANCE")
|
||||
|
|
@ -108,9 +110,10 @@ public class AlertPluginInstanceController extends BaseController {
|
|||
@PostMapping(value = "/test-send")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(SEND_TEST_ALERT_PLUGIN_INSTANCE_ERROR)
|
||||
public Result testSendAlertPluginInstance(@RequestParam(value = "pluginDefineId") int pluginDefineId,
|
||||
@RequestParam(value = "pluginInstanceParams") String pluginInstanceParams) {
|
||||
return alertPluginInstanceService.testSend(pluginDefineId, pluginInstanceParams);
|
||||
public Result<Boolean> testSendAlertPluginInstance(@RequestParam(value = "pluginDefineId") int pluginDefineId,
|
||||
@RequestParam(value = "pluginInstanceParams") String pluginInstanceParams) {
|
||||
alertPluginInstanceService.testSend(pluginDefineId, pluginInstanceParams);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -131,14 +134,14 @@ public class AlertPluginInstanceController extends BaseController {
|
|||
@PutMapping(value = "/{id}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(UPDATE_ALERT_PLUGIN_INSTANCE_ERROR)
|
||||
public Result updateAlertPluginInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id,
|
||||
@RequestParam(value = "instanceName") String instanceName,
|
||||
@RequestParam(value = "warningType") WarningType warningType,
|
||||
@RequestParam(value = "pluginInstanceParams") String pluginInstanceParams) {
|
||||
Map<String, Object> result =
|
||||
alertPluginInstanceService.update(loginUser, id, instanceName, warningType, pluginInstanceParams);
|
||||
return returnDataList(result);
|
||||
public Result<AlertPluginInstance> updateAlertPluginInstanceById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id,
|
||||
@RequestParam(value = "instanceName") String instanceName,
|
||||
@RequestParam(value = "warningType") WarningType warningType,
|
||||
@RequestParam(value = "pluginInstanceParams") String pluginInstanceParams) {
|
||||
AlertPluginInstance alertPluginInstance =
|
||||
alertPluginInstanceService.updateById(loginUser, id, instanceName, warningType, pluginInstanceParams);
|
||||
return Result.success(alertPluginInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -155,11 +158,11 @@ public class AlertPluginInstanceController extends BaseController {
|
|||
@DeleteMapping(value = "/{id}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(DELETE_ALERT_PLUGIN_INSTANCE_ERROR)
|
||||
public Result deleteAlertPluginInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id) {
|
||||
public Result<Boolean> deleteAlertPluginInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id) {
|
||||
|
||||
Map<String, Object> result = alertPluginInstanceService.delete(loginUser, id);
|
||||
return returnDataList(result);
|
||||
alertPluginInstanceService.deleteById(loginUser, id);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -173,10 +176,10 @@ public class AlertPluginInstanceController extends BaseController {
|
|||
@GetMapping(value = "/{id}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(GET_ALERT_PLUGIN_INSTANCE_ERROR)
|
||||
public Result getAlertPluginInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id) {
|
||||
Map<String, Object> result = alertPluginInstanceService.get(loginUser, id);
|
||||
return returnDataList(result);
|
||||
public Result<AlertPluginInstance> getAlertPluginInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id) {
|
||||
AlertPluginInstance alertPluginInstance = alertPluginInstanceService.getById(loginUser, id);
|
||||
return Result.success(alertPluginInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -189,9 +192,9 @@ public class AlertPluginInstanceController extends BaseController {
|
|||
@GetMapping(value = "/list")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_ALL_ALERT_PLUGIN_INSTANCE_ERROR)
|
||||
public Result getAlertPluginInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
Map<String, Object> result = alertPluginInstanceService.queryAll();
|
||||
return returnDataList(result);
|
||||
public Result<List<AlertPluginInstanceVO>> getAlertPluginInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
List<AlertPluginInstanceVO> alertPluginInstanceVOS = alertPluginInstanceService.queryAll();
|
||||
return Result.success(alertPluginInstanceVOS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -237,16 +240,15 @@ public class AlertPluginInstanceController extends BaseController {
|
|||
@GetMapping()
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(LIST_PAGING_ALERT_PLUGIN_INSTANCE_ERROR)
|
||||
public Result listPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
public Result<PageInfo<AlertPluginInstanceVO>> listPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
return alertPluginInstanceService.listPaging(loginUser, searchVal, pageNo, pageSize);
|
||||
PageInfo<AlertPluginInstanceVO> alertPluginInstanceVOPageInfo =
|
||||
alertPluginInstanceService.listPaging(loginUser, searchVal, pageNo, pageSize);
|
||||
return Result.success(alertPluginInstanceVOPageInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,10 @@ package org.apache.dolphinscheduler.api.controller;
|
|||
|
||||
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_AUDIT_LOG_LIST_PAGING;
|
||||
|
||||
import org.apache.dolphinscheduler.api.dto.AuditDto;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
||||
import org.apache.dolphinscheduler.api.service.AuditService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
|
||||
|
|
@ -76,20 +78,24 @@ public class AuditLogController extends BaseController {
|
|||
@GetMapping(value = "/audit-log-list")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_AUDIT_LOG_LIST_PAGING)
|
||||
public Result queryAuditLogListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize,
|
||||
@RequestParam(value = "resourceType", required = false) AuditResourceType resourceType,
|
||||
@RequestParam(value = "operationType", required = false) AuditOperationType operationType,
|
||||
@RequestParam(value = "startDate", required = false) String startDate,
|
||||
@RequestParam(value = "endDate", required = false) String endDate,
|
||||
@RequestParam(value = "userName", required = false) String userName) {
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
result = auditService.queryLogListPaging(loginUser, resourceType, operationType, startDate, endDate, userName,
|
||||
pageNo, pageSize);
|
||||
return result;
|
||||
public Result<PageInfo<AuditDto>> queryAuditLogListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize,
|
||||
@RequestParam(value = "resourceType", required = false) AuditResourceType resourceType,
|
||||
@RequestParam(value = "operationType", required = false) AuditOperationType operationType,
|
||||
@RequestParam(value = "startDate", required = false) String startDate,
|
||||
@RequestParam(value = "endDate", required = false) String endDate,
|
||||
@RequestParam(value = "userName", required = false) String userName) {
|
||||
checkPageParams(pageNo, pageSize);
|
||||
PageInfo<AuditDto> auditDtoPageInfo = auditService.queryLogListPaging(
|
||||
loginUser,
|
||||
resourceType,
|
||||
operationType,
|
||||
startDate,
|
||||
endDate,
|
||||
userName,
|
||||
pageNo,
|
||||
pageSize);
|
||||
return Result.success(auditDtoPageInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import static org.apache.dolphinscheduler.common.constants.Constants.HTTP_X_FORW
|
|||
import static org.apache.dolphinscheduler.common.constants.Constants.HTTP_X_REAL_IP;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
|
||||
|
|
@ -42,25 +43,17 @@ public class BaseController {
|
|||
/**
|
||||
* check params
|
||||
*
|
||||
* @param pageNo page number
|
||||
* @param pageNo page number
|
||||
* @param pageSize page size
|
||||
* @return check result code
|
||||
* @throws ServiceException exception
|
||||
*/
|
||||
// todo: directly throw exception
|
||||
public <T> Result<T> checkPageParams(int pageNo, int pageSize) {
|
||||
Result<T> result = new Result<>();
|
||||
Status resultEnum = Status.SUCCESS;
|
||||
String msg = Status.SUCCESS.getMsg();
|
||||
public void checkPageParams(int pageNo, int pageSize) throws ServiceException {
|
||||
if (pageNo <= 0) {
|
||||
resultEnum = Status.REQUEST_PARAMS_NOT_VALID_ERROR;
|
||||
msg = MessageFormat.format(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getMsg(), Constants.PAGE_NUMBER);
|
||||
} else if (pageSize <= 0) {
|
||||
resultEnum = Status.REQUEST_PARAMS_NOT_VALID_ERROR;
|
||||
msg = MessageFormat.format(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getMsg(), Constants.PAGE_SIZE);
|
||||
throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.PAGE_NUMBER);
|
||||
}
|
||||
if (pageSize <= 0) {
|
||||
throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.PAGE_SIZE);
|
||||
}
|
||||
result.setCode(resultEnum.getCode());
|
||||
result.setMsg(msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -24,14 +24,17 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_CLUSTER_ERROR;
|
|||
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_CLUSTER_ERROR;
|
||||
import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_CLUSTER_ERROR;
|
||||
|
||||
import org.apache.dolphinscheduler.api.dto.ClusterDto;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
||||
import org.apache.dolphinscheduler.api.service.ClusterService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.dao.entity.Cluster;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
|
@ -78,13 +81,13 @@ public class ClusterController extends BaseController {
|
|||
@PostMapping(value = "/create")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ApiException(CREATE_CLUSTER_ERROR)
|
||||
public Result createProject(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("name") String name,
|
||||
@RequestParam("config") String config,
|
||||
@RequestParam(value = "description", required = false) String description) {
|
||||
public Result<Long> createProject(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("name") String name,
|
||||
@RequestParam("config") String config,
|
||||
@RequestParam(value = "description", required = false) String description) {
|
||||
|
||||
Map<String, Object> result = clusterService.createCluster(loginUser, name, config, description);
|
||||
return returnDataList(result);
|
||||
Long clusterCode = clusterService.createCluster(loginUser, name, config, description);
|
||||
return Result.success(clusterCode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -107,13 +110,13 @@ public class ClusterController extends BaseController {
|
|||
@PostMapping(value = "/update")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(UPDATE_CLUSTER_ERROR)
|
||||
public Result updateCluster(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("code") Long code,
|
||||
@RequestParam("name") String name,
|
||||
@RequestParam("config") String config,
|
||||
@RequestParam(value = "description", required = false) String description) {
|
||||
Map<String, Object> result = clusterService.updateClusterByCode(loginUser, code, name, config, description);
|
||||
return returnDataList(result);
|
||||
public Result<Cluster> updateCluster(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("code") Long code,
|
||||
@RequestParam("name") String name,
|
||||
@RequestParam("config") String config,
|
||||
@RequestParam(value = "description", required = false) String description) {
|
||||
Cluster cluster = clusterService.updateClusterByCode(loginUser, code, name, config, description);
|
||||
return Result.success(cluster);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -129,11 +132,11 @@ public class ClusterController extends BaseController {
|
|||
@GetMapping(value = "/query-by-code")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_CLUSTER_BY_CODE_ERROR)
|
||||
public Result queryClusterByCode(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("clusterCode") Long clusterCode) {
|
||||
public Result<ClusterDto> queryClusterByCode(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("clusterCode") Long clusterCode) {
|
||||
|
||||
Map<String, Object> result = clusterService.queryClusterByCode(clusterCode);
|
||||
return returnDataList(result);
|
||||
ClusterDto clusterDto = clusterService.queryClusterByCode(clusterCode);
|
||||
return Result.success(clusterDto);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -153,18 +156,15 @@ public class ClusterController extends BaseController {
|
|||
@GetMapping(value = "/list-paging")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_CLUSTER_ERROR)
|
||||
public Result queryClusterListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam("pageSize") Integer pageSize,
|
||||
@RequestParam("pageNo") Integer pageNo) {
|
||||
public Result<PageInfo<ClusterDto>> queryClusterListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam("pageSize") Integer pageSize,
|
||||
@RequestParam("pageNo") Integer pageNo) {
|
||||
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
result = clusterService.queryClusterListPaging(pageNo, pageSize, searchVal);
|
||||
return result;
|
||||
PageInfo<ClusterDto> clusterDtoPageInfo = clusterService.queryClusterListPaging(pageNo, pageSize, searchVal);
|
||||
return Result.success(clusterDtoPageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -181,11 +181,11 @@ public class ClusterController extends BaseController {
|
|||
@PostMapping(value = "/delete")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(DELETE_CLUSTER_ERROR)
|
||||
public Result deleteCluster(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("clusterCode") Long clusterCode) {
|
||||
public Result<Boolean> deleteCluster(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("clusterCode") Long clusterCode) {
|
||||
|
||||
Map<String, Object> result = clusterService.deleteClusterByCode(loginUser, clusterCode);
|
||||
return returnDataList(result);
|
||||
clusterService.deleteClusterByCode(loginUser, clusterCode);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -198,9 +198,9 @@ public class ClusterController extends BaseController {
|
|||
@GetMapping(value = "/query-cluster-list")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_CLUSTER_ERROR)
|
||||
public Result queryAllClusterList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
Map<String, Object> result = clusterService.queryAllClusterList();
|
||||
return returnDataList(result);
|
||||
public Result<List<ClusterDto>> queryAllClusterList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
List<ClusterDto> clusterDtos = clusterService.queryAllClusterList();
|
||||
return Result.success(clusterDtos);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -217,9 +217,9 @@ public class ClusterController extends BaseController {
|
|||
@PostMapping(value = "/verify-cluster")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(VERIFY_CLUSTER_ERROR)
|
||||
public Result verifyCluster(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "clusterName") String clusterName) {
|
||||
Map<String, Object> result = clusterService.verifyCluster(clusterName);
|
||||
return returnDataList(result);
|
||||
public Result<Boolean> verifyCluster(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "clusterName") String clusterName) {
|
||||
clusterService.verifyCluster(clusterName);
|
||||
return Result.success(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,12 +23,16 @@ import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_INSTANC
|
|||
import static org.apache.dolphinscheduler.api.enums.Status.QUEUE_COUNT_ERROR;
|
||||
import static org.apache.dolphinscheduler.api.enums.Status.TASK_INSTANCE_STATE_COUNT_ERROR;
|
||||
|
||||
import org.apache.dolphinscheduler.api.dto.CommandStateCount;
|
||||
import org.apache.dolphinscheduler.api.dto.DefineUserDto;
|
||||
import org.apache.dolphinscheduler.api.dto.TaskCountDto;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
||||
import org.apache.dolphinscheduler.api.service.DataAnalysisService;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -75,14 +79,14 @@ public class DataAnalysisController extends BaseController {
|
|||
@GetMapping(value = "/task-state-count")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(TASK_INSTANCE_STATE_COUNT_ERROR)
|
||||
public Result countTaskState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "startDate", required = false) String startDate,
|
||||
@RequestParam(value = "endDate", required = false) String endDate,
|
||||
@RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) {
|
||||
public Result<TaskCountDto> countTaskState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "startDate", required = false) String startDate,
|
||||
@RequestParam(value = "endDate", required = false) String endDate,
|
||||
@RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) {
|
||||
|
||||
Map<String, Object> result =
|
||||
TaskCountDto taskCountDto =
|
||||
dataAnalysisService.countTaskStateByProject(loginUser, projectCode, startDate, endDate);
|
||||
return returnDataList(result);
|
||||
return Result.success(taskCountDto);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -103,14 +107,14 @@ public class DataAnalysisController extends BaseController {
|
|||
@GetMapping(value = "/process-state-count")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(COUNT_PROCESS_INSTANCE_STATE_ERROR)
|
||||
public Result countProcessInstanceState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "startDate", required = false) String startDate,
|
||||
@RequestParam(value = "endDate", required = false) String endDate,
|
||||
@RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) {
|
||||
public Result<TaskCountDto> countProcessInstanceState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "startDate", required = false) String startDate,
|
||||
@RequestParam(value = "endDate", required = false) String endDate,
|
||||
@RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) {
|
||||
|
||||
Map<String, Object> result =
|
||||
TaskCountDto taskCountDto =
|
||||
dataAnalysisService.countProcessInstanceStateByProject(loginUser, projectCode, startDate, endDate);
|
||||
return returnDataList(result);
|
||||
return Result.success(taskCountDto);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -127,11 +131,11 @@ public class DataAnalysisController extends BaseController {
|
|||
@GetMapping(value = "/define-user-count")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
|
||||
public Result countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) {
|
||||
public Result<DefineUserDto> countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) {
|
||||
|
||||
Map<String, Object> result = dataAnalysisService.countDefinitionByUser(loginUser, projectCode);
|
||||
return returnDataList(result);
|
||||
DefineUserDto defineUserDto = dataAnalysisService.countDefinitionByUser(loginUser, projectCode);
|
||||
return Result.success(defineUserDto);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -144,10 +148,10 @@ public class DataAnalysisController extends BaseController {
|
|||
@GetMapping(value = "/command-state-count")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(COMMAND_STATE_COUNT_ERROR)
|
||||
public Result countCommandState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
public Result<List<CommandStateCount>> countCommandState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
|
||||
Map<String, Object> result = dataAnalysisService.countCommandState(loginUser);
|
||||
return returnDataList(result);
|
||||
List<CommandStateCount> commandStateCounts = dataAnalysisService.countCommandState(loginUser);
|
||||
return Result.success(commandStateCounts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -160,9 +164,9 @@ public class DataAnalysisController extends BaseController {
|
|||
@GetMapping(value = "/queue-count")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUEUE_COUNT_ERROR)
|
||||
public Result countQueueState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
public Result<Map<String, Integer>> countQueueState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
|
||||
Map<String, Object> result = dataAnalysisService.countQueueState(loginUser);
|
||||
return returnDataList(result);
|
||||
Map<String, Integer> stringIntegerMap = dataAnalysisService.countQueueState(loginUser);
|
||||
return Result.success(stringIntegerMap);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,12 +26,16 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_RULE_LIST_PAGIN
|
|||
import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
||||
import org.apache.dolphinscheduler.api.service.DqExecuteResultService;
|
||||
import org.apache.dolphinscheduler.api.service.DqRuleService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.dao.entity.DqExecuteResult;
|
||||
import org.apache.dolphinscheduler.dao.entity.DqRule;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
|
||||
import org.apache.dolphinscheduler.spi.params.base.ParamsOptions;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
|
@ -74,9 +78,9 @@ public class DataQualityController extends BaseController {
|
|||
@GetMapping(value = "/getRuleFormCreateJson")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(GET_RULE_FORM_CREATE_JSON_ERROR)
|
||||
public Result getRuleFormCreateJsonById(@RequestParam(value = "ruleId") int ruleId) {
|
||||
Map<String, Object> result = dqRuleService.getRuleFormCreateJsonById(ruleId);
|
||||
return returnDataList(result);
|
||||
public Result<String> getRuleFormCreateJsonById(@RequestParam(value = "ruleId") int ruleId) {
|
||||
String ruleFormCreateJsonById = dqRuleService.getRuleFormCreateJsonById(ruleId);
|
||||
return Result.success(ruleFormCreateJsonById);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -100,33 +104,33 @@ public class DataQualityController extends BaseController {
|
|||
@GetMapping(value = "/rule/page")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_RULE_LIST_PAGING_ERROR)
|
||||
public Result queryRuleListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam(value = "ruleType", required = false) Integer ruleType,
|
||||
@RequestParam(value = "startDate", required = false) String startTime,
|
||||
@RequestParam(value = "endDate", required = false) String endTime,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
public Result<PageInfo<DqRule>> queryRuleListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam(value = "ruleType", required = false) Integer ruleType,
|
||||
@RequestParam(value = "startDate", required = false) String startTime,
|
||||
@RequestParam(value = "endDate", required = false) String endTime,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
|
||||
return dqRuleService.queryRuleListPaging(loginUser, searchVal, ruleType, startTime, endTime, pageNo, pageSize);
|
||||
PageInfo<DqRule> dqRulePageInfo =
|
||||
dqRuleService.queryRuleListPaging(loginUser, searchVal, ruleType, startTime, endTime, pageNo, pageSize);
|
||||
return Result.success(dqRulePageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* query all rule list
|
||||
*
|
||||
* @return rule list
|
||||
*/
|
||||
@Operation(summary = "queryRuleList", description = "QUERY_RULE_LIST_NOTES")
|
||||
@GetMapping(value = "/ruleList")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_RULE_LIST_ERROR)
|
||||
public Result queryRuleList() {
|
||||
Map<String, Object> result = dqRuleService.queryAllRuleList();
|
||||
return returnDataList(result);
|
||||
public Result<List<DqRule>> queryRuleList() {
|
||||
List<DqRule> dqRules = dqRuleService.queryAllRuleList();
|
||||
return Result.success(dqRules);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -155,23 +159,21 @@ public class DataQualityController extends BaseController {
|
|||
@GetMapping(value = "/result/page")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_EXECUTE_RESULT_LIST_PAGING_ERROR)
|
||||
public Result queryExecuteResultListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam(value = "ruleType", required = false) Integer ruleType,
|
||||
@RequestParam(value = "state", required = false) Integer state,
|
||||
@RequestParam(value = "startDate", required = false) String startTime,
|
||||
@RequestParam(value = "endDate", required = false) String endTime,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
public Result<PageInfo<DqExecuteResult>> queryExecuteResultListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam(value = "ruleType", required = false) Integer ruleType,
|
||||
@RequestParam(value = "state", required = false) Integer state,
|
||||
@RequestParam(value = "startDate", required = false) String startTime,
|
||||
@RequestParam(value = "endDate", required = false) String endTime,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
|
||||
return dqExecuteResultService.queryResultListPaging(loginUser, searchVal, state, ruleType, startTime, endTime,
|
||||
pageNo, pageSize);
|
||||
PageInfo<DqExecuteResult> dqExecuteResultPageInfo = dqExecuteResultService.queryResultListPaging(loginUser,
|
||||
searchVal, state, ruleType, startTime, endTime, pageNo, pageSize);
|
||||
return Result.success(dqExecuteResultPageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -186,8 +188,8 @@ public class DataQualityController extends BaseController {
|
|||
@GetMapping(value = "/getDatasourceOptionsById")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(GET_DATASOURCE_OPTIONS_ERROR)
|
||||
public Result getDatasourceOptionsById(@RequestParam(value = "datasourceId") int datasourceId) {
|
||||
Map<String, Object> result = dqRuleService.getDatasourceOptionsById(datasourceId);
|
||||
return returnDataList(result);
|
||||
public Result<List<ParamsOptions>> getDatasourceOptionsById(@RequestParam(value = "datasourceId") int datasourceId) {
|
||||
List<ParamsOptions> paramsOptions = dqRuleService.getDatasourceOptionsById(datasourceId);
|
||||
return Result.success(paramsOptions);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,10 +92,11 @@ public class DataSourceController extends BaseController {
|
|||
@PostMapping()
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ApiException(CREATE_DATASOURCE_ERROR)
|
||||
public Result<Object> createDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@Parameter(name = "dataSourceParam", description = "DATA_SOURCE_PARAM", required = true) @RequestBody String jsonStr) {
|
||||
public Result<DataSource> createDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@Parameter(name = "dataSourceParam", description = "DATA_SOURCE_PARAM", required = true) @RequestBody String jsonStr) {
|
||||
BaseDataSourceParamDTO dataSourceParam = DataSourceUtils.buildDatasourceParam(jsonStr);
|
||||
return dataSourceService.createDataSource(loginUser, dataSourceParam);
|
||||
DataSource dataSource = dataSourceService.createDataSource(loginUser, dataSourceParam);
|
||||
return Result.success(dataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -115,12 +116,13 @@ public class DataSourceController extends BaseController {
|
|||
@PutMapping(value = "/{id}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(UPDATE_DATASOURCE_ERROR)
|
||||
public Result<Object> updateDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") Integer id,
|
||||
@RequestBody String jsonStr) {
|
||||
public Result<DataSource> updateDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") Integer id,
|
||||
@RequestBody String jsonStr) {
|
||||
BaseDataSourceParamDTO dataSourceParam = DataSourceUtils.buildDatasourceParam(jsonStr);
|
||||
dataSourceParam.setId(id);
|
||||
return dataSourceService.updateDataSource(dataSourceParam.getId(), loginUser, dataSourceParam);
|
||||
DataSource dataSource = dataSourceService.updateDataSource(loginUser, dataSourceParam);
|
||||
return Result.success(dataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -186,10 +188,7 @@ public class DataSourceController extends BaseController {
|
|||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
Result<Object> result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
PageInfo<DataSource> pageInfo =
|
||||
dataSourceService.queryDataSourceListPaging(loginUser, searchVal, pageNo, pageSize);
|
||||
|
|
@ -208,12 +207,13 @@ public class DataSourceController extends BaseController {
|
|||
@PostMapping(value = "/connect")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(CONNECT_DATASOURCE_FAILURE)
|
||||
public Result<Object> connectDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "dataSourceParam") @RequestBody String jsonStr) {
|
||||
public Result<Boolean> connectDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "dataSourceParam") @RequestBody String jsonStr) {
|
||||
BaseDataSourceParamDTO dataSourceParam = DataSourceUtils.buildDatasourceParam(jsonStr);
|
||||
DataSourceUtils.checkDatasourceParam(dataSourceParam);
|
||||
ConnectionParam connectionParams = DataSourceUtils.buildConnectionParams(dataSourceParam);
|
||||
return dataSourceService.checkConnection(dataSourceParam.getType(), connectionParams);
|
||||
dataSourceService.checkConnection(dataSourceParam.getType(), connectionParams);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -230,9 +230,10 @@ public class DataSourceController extends BaseController {
|
|||
@GetMapping(value = "/{id}/connect-test")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(CONNECTION_TEST_FAILURE)
|
||||
public Result<Object> connectionTest(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable("id") int id) {
|
||||
return dataSourceService.connectionTest(id);
|
||||
public Result<Boolean> connectionTest(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable("id") int id) {
|
||||
dataSourceService.connectionTest(id);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -249,9 +250,10 @@ public class DataSourceController extends BaseController {
|
|||
@DeleteMapping(value = "/{id}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(DELETE_DATA_SOURCE_FAILURE)
|
||||
public Result<Object> deleteDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable("id") int id) {
|
||||
return dataSourceService.delete(loginUser, id);
|
||||
public Result<Boolean> deleteDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable("id") int id) {
|
||||
dataSourceService.delete(loginUser, id);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -268,9 +270,10 @@ public class DataSourceController extends BaseController {
|
|||
@GetMapping(value = "/verify-name")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(VERIFY_DATASOURCE_NAME_FAILURE)
|
||||
public Result<Object> verifyDataSourceName(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "name") String name) {
|
||||
return dataSourceService.verifyDataSourceName(name);
|
||||
public Result<Boolean> verifyDataSourceName(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "name") String name) {
|
||||
dataSourceService.verifyDataSourceName(name);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
|||
import org.apache.dolphinscheduler.api.service.EnvironmentService;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.dao.entity.Environment;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
|
||||
|
||||
|
|
@ -79,15 +80,14 @@ public class EnvironmentController extends BaseController {
|
|||
@PostMapping(value = "/create")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ApiException(CREATE_ENVIRONMENT_ERROR)
|
||||
public Result createEnvironment(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("name") String name,
|
||||
@RequestParam("config") String config,
|
||||
@RequestParam(value = "description", required = false) String description,
|
||||
@RequestParam(value = "workerGroups", required = false) String workerGroups) {
|
||||
public Result<Long> createEnvironment(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("name") String name,
|
||||
@RequestParam("config") String config,
|
||||
@RequestParam(value = "description", required = false) String description,
|
||||
@RequestParam(value = "workerGroups", required = false) String workerGroups) {
|
||||
|
||||
Map<String, Object> result =
|
||||
environmentService.createEnvironment(loginUser, name, config, description, workerGroups);
|
||||
return returnDataList(result);
|
||||
Long environmentCode = environmentService.createEnvironment(loginUser, name, config, description, workerGroups);
|
||||
return Result.success(environmentCode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -111,15 +111,15 @@ public class EnvironmentController extends BaseController {
|
|||
@PostMapping(value = "/update")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(UPDATE_ENVIRONMENT_ERROR)
|
||||
public Result updateEnvironment(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("code") Long code,
|
||||
@RequestParam("name") String name,
|
||||
@RequestParam("config") String config,
|
||||
@RequestParam(value = "description", required = false) String description,
|
||||
@RequestParam(value = "workerGroups", required = false) String workerGroups) {
|
||||
Map<String, Object> result =
|
||||
public Result<Environment> updateEnvironment(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("code") Long code,
|
||||
@RequestParam("name") String name,
|
||||
@RequestParam("config") String config,
|
||||
@RequestParam(value = "description", required = false) String description,
|
||||
@RequestParam(value = "workerGroups", required = false) String workerGroups) {
|
||||
Environment environment =
|
||||
environmentService.updateEnvironmentByCode(loginUser, code, name, config, description, workerGroups);
|
||||
return returnDataList(result);
|
||||
return Result.success(environment);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -164,13 +164,9 @@ public class EnvironmentController extends BaseController {
|
|||
@RequestParam("pageSize") Integer pageSize,
|
||||
@RequestParam("pageNo") Integer pageNo) {
|
||||
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
result = environmentService.queryEnvironmentListPaging(loginUser, pageNo, pageSize, searchVal);
|
||||
return result;
|
||||
return environmentService.queryEnvironmentListPaging(loginUser, pageNo, pageSize, searchVal);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -438,16 +438,16 @@ public class ExecutorController extends BaseController {
|
|||
@PostMapping(value = "/task-instance/{code}/start")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(START_PROCESS_INSTANCE_ERROR)
|
||||
public Result startStreamTaskInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
|
||||
@Parameter(name = "code", description = "TASK_CODE", required = true) @PathVariable long code,
|
||||
@RequestParam(value = "version", required = true) int version,
|
||||
@RequestParam(value = "warningGroupId", required = false, defaultValue = "0") Integer warningGroupId,
|
||||
@RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup,
|
||||
@RequestParam(value = "tenantCode", required = false, defaultValue = "default") String tenantCode,
|
||||
@RequestParam(value = "environmentCode", required = false, defaultValue = "-1") Long environmentCode,
|
||||
@RequestParam(value = "startParams", required = false) String startParams,
|
||||
@RequestParam(value = "dryRun", defaultValue = "0", required = false) int dryRun) {
|
||||
public Result<Boolean> startStreamTaskInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
|
||||
@Parameter(name = "code", description = "TASK_CODE", required = true) @PathVariable long code,
|
||||
@RequestParam(value = "version", required = true) int version,
|
||||
@RequestParam(value = "warningGroupId", required = false, defaultValue = "0") Integer warningGroupId,
|
||||
@RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup,
|
||||
@RequestParam(value = "tenantCode", required = false, defaultValue = "default") String tenantCode,
|
||||
@RequestParam(value = "environmentCode", required = false, defaultValue = "-1") Long environmentCode,
|
||||
@RequestParam(value = "startParams", required = false) String startParams,
|
||||
@RequestParam(value = "dryRun", defaultValue = "0", required = false) int dryRun) {
|
||||
|
||||
Map<String, String> startParamMap = null;
|
||||
if (startParams != null) {
|
||||
|
|
@ -456,9 +456,9 @@ public class ExecutorController extends BaseController {
|
|||
|
||||
log.info("Start to execute stream task instance, projectCode:{}, taskDefinitionCode:{}, taskVersion:{}.",
|
||||
projectCode, code, version);
|
||||
Map<String, Object> result = execService.execStreamTaskInstance(loginUser, projectCode, code, version,
|
||||
warningGroupId, workerGroup, tenantCode, environmentCode, startParamMap, dryRun);
|
||||
return returnDataList(result);
|
||||
execService.execStreamTaskInstance(loginUser, projectCode, code, version, warningGroupId, workerGroup,
|
||||
tenantCode, environmentCode, startParamMap, dryRun);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -86,13 +86,9 @@ public class K8sNamespaceController extends BaseController {
|
|||
@RequestParam("pageSize") Integer pageSize,
|
||||
@RequestParam("pageNo") Integer pageNo) {
|
||||
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
result = k8sNamespaceService.queryListPaging(loginUser, searchVal, pageNo, pageSize);
|
||||
return result;
|
||||
return k8sNamespaceService.queryListPaging(loginUser, searchVal, pageNo, pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -131,7 +131,8 @@ public class LoggerController extends BaseController {
|
|||
@RequestParam(value = "taskInstanceId") int taskInstanceId,
|
||||
@RequestParam(value = "skipLineNum") int skipNum,
|
||||
@RequestParam(value = "limit") int limit) {
|
||||
return returnDataList(loggerService.queryLog(loginUser, projectCode, taskInstanceId, skipNum, limit));
|
||||
String log = loggerService.queryLog(loginUser, projectCode, taskInstanceId, skipNum, limit);
|
||||
return Result.success(log);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -25,9 +25,12 @@ import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
|||
import org.apache.dolphinscheduler.api.service.MonitorService;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.model.Server;
|
||||
import org.apache.dolphinscheduler.common.model.WorkerServerModel;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMetrics;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
|
@ -62,9 +65,9 @@ public class MonitorController extends BaseController {
|
|||
@GetMapping(value = "/masters")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(LIST_MASTERS_ERROR)
|
||||
public Result listMaster(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
Map<String, Object> result = monitorService.queryMaster(loginUser);
|
||||
return returnDataList(result);
|
||||
public Result<List<Server>> listMaster(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
List<Server> servers = monitorService.queryMaster(loginUser);
|
||||
return Result.success(servers);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -77,9 +80,9 @@ public class MonitorController extends BaseController {
|
|||
@GetMapping(value = "/workers")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(LIST_WORKERS_ERROR)
|
||||
public Result listWorker(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
Map<String, Object> result = monitorService.queryWorker(loginUser);
|
||||
return returnDataList(result);
|
||||
public Result<List<WorkerServerModel>> listWorker(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
List<WorkerServerModel> workerServerModels = monitorService.queryWorker(loginUser);
|
||||
return Result.success(workerServerModels);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -92,9 +95,9 @@ public class MonitorController extends BaseController {
|
|||
@GetMapping(value = "/databases")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_DATABASE_STATE_ERROR)
|
||||
public Result queryDatabaseState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
Map<String, Object> result = monitorService.queryDatabaseState(loginUser);
|
||||
return returnDataList(result);
|
||||
public Result<List<DatabaseMetrics>> queryDatabaseState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
List<DatabaseMetrics> databaseMetrics = monitorService.queryDatabaseState(loginUser);
|
||||
return Result.success(databaseMetrics);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -286,14 +286,9 @@ public class ProcessDefinitionController extends BaseController {
|
|||
@RequestParam(value = "pageSize") int pageSize,
|
||||
@PathVariable(value = "code") long code) {
|
||||
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
result = processDefinitionService.queryProcessDefinitionVersions(loginUser, projectCode, pageNo, pageSize,
|
||||
checkPageParams(pageNo, pageSize);
|
||||
return processDefinitionService.queryProcessDefinitionVersions(loginUser, projectCode, pageNo, pageSize,
|
||||
code);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -487,10 +482,7 @@ public class ProcessDefinitionController extends BaseController {
|
|||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
|
||||
Result<PageInfo<ProcessDefinition>> result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
|
||||
PageInfo<ProcessDefinition> pageInfo = processDefinitionService.queryProcessDefinitionListPaging(
|
||||
|
|
|
|||
|
|
@ -116,15 +116,11 @@ public class ProcessInstanceController extends BaseController {
|
|||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
result = processInstanceService.queryProcessInstanceList(loginUser, projectCode, processDefineCode, startTime,
|
||||
return processInstanceService.queryProcessInstanceList(loginUser, projectCode, processDefineCode, startTime,
|
||||
endTime,
|
||||
searchVal, executorName, stateType, host, otherParamsJson, pageNo, pageSize);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -156,14 +156,9 @@ public class ProjectController extends BaseController {
|
|||
@RequestParam("pageSize") Integer pageSize,
|
||||
@RequestParam("pageNo") Integer pageNo) {
|
||||
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
log.warn("Pagination parameters check failed, pageNo:{}, pageSize:{}", pageNo, pageSize);
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
result = projectService.queryProjectListPaging(loginUser, pageSize, pageNo, searchVal);
|
||||
return result;
|
||||
return projectService.queryProjectListPaging(loginUser, pageSize, pageNo, searchVal);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -192,14 +187,10 @@ public class ProjectController extends BaseController {
|
|||
@RequestParam("pageSize") Integer pageSize,
|
||||
@RequestParam("pageNo") Integer pageNo) {
|
||||
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
result = projectService.queryProjectWithAuthorizedLevelListPaging(userId, loginUser, pageSize, pageNo,
|
||||
return projectService.queryProjectWithAuthorizedLevelListPaging(userId, loginUser, pageSize, pageNo,
|
||||
searchVal);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -136,11 +136,7 @@ public class ProjectParameterController extends BaseController {
|
|||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
log.warn("Pagination parameters check failed, pageNo:{}, pageSize:{}", pageNo, pageSize);
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
return projectParameterService.queryProjectParameterListPaging(loginUser, projectCode, pageSize, pageNo,
|
||||
searchVal);
|
||||
|
|
|
|||
|
|
@ -25,12 +25,14 @@ import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_QUEUE_ERROR;
|
|||
|
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
||||
import org.apache.dolphinscheduler.api.service.QueueService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.dao.entity.Queue;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
|
@ -72,8 +74,9 @@ public class QueueController extends BaseController {
|
|||
@GetMapping(value = "/list")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_QUEUE_LIST_ERROR)
|
||||
public Result queryList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
return queueService.queryList(loginUser);
|
||||
public Result<List<Queue>> queryList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
List<Queue> queues = queueService.queryList(loginUser);
|
||||
return Result.success(queues);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -94,18 +97,15 @@ public class QueueController extends BaseController {
|
|||
@GetMapping()
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_QUEUE_LIST_ERROR)
|
||||
public Result queryQueueListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
public Result<PageInfo<Queue>> queryQueueListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
checkPageParams(pageNo, pageSize);
|
||||
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
result = queueService.queryList(loginUser, searchVal, pageNo, pageSize);
|
||||
return result;
|
||||
PageInfo<Queue> queuePageInfo = queueService.queryList(loginUser, searchVal, pageNo, pageSize);
|
||||
return Result.success(queuePageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -124,10 +124,10 @@ public class QueueController extends BaseController {
|
|||
@PostMapping()
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ApiException(CREATE_QUEUE_ERROR)
|
||||
public Result createQueue(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "queue") String queue,
|
||||
@RequestParam(value = "queueName") String queueName) {
|
||||
return queueService.createQueue(loginUser, queue, queueName);
|
||||
public Result<Queue> createQueue(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "queue") String queue,
|
||||
@RequestParam(value = "queueName") String queueName) {
|
||||
return Result.success(queueService.createQueue(loginUser, queue, queueName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -148,11 +148,11 @@ public class QueueController extends BaseController {
|
|||
@PutMapping(value = "/{id}")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ApiException(UPDATE_QUEUE_ERROR)
|
||||
public Result updateQueue(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id,
|
||||
@RequestParam(value = "queue") String queue,
|
||||
@RequestParam(value = "queueName") String queueName) {
|
||||
return queueService.updateQueue(loginUser, id, queue, queueName);
|
||||
public Result<Queue> updateQueue(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id,
|
||||
@RequestParam(value = "queue") String queue,
|
||||
@RequestParam(value = "queueName") String queueName) {
|
||||
return Result.success(queueService.updateQueue(loginUser, id, queue, queueName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -169,10 +169,10 @@ public class QueueController extends BaseController {
|
|||
@DeleteMapping(value = "/{id}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(DELETE_QUEUE_BY_ID_ERROR)
|
||||
public Result deleteQueueById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id) throws Exception {
|
||||
Map<String, Object> result = queueService.deleteQueueById(loginUser, id);
|
||||
return returnDataList(result);
|
||||
public Result<Boolean> deleteQueueById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id) throws Exception {
|
||||
queueService.deleteQueueById(loginUser, id);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -191,9 +191,10 @@ public class QueueController extends BaseController {
|
|||
@PostMapping(value = "/verify")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(VERIFY_QUEUE_ERROR)
|
||||
public Result verifyQueue(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "queue") String queue,
|
||||
@RequestParam(value = "queueName") String queueName) {
|
||||
return queueService.verifyQueue(queue, queueName);
|
||||
public Result<Boolean> verifyQueue(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "queue") String queue,
|
||||
@RequestParam(value = "queueName") String queueName) {
|
||||
queueService.verifyQueue(queue, queueName);
|
||||
return Result.success(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -227,15 +227,11 @@ public class ResourcesController extends BaseController {
|
|||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
Result<PageInfo<StorageEntity>> result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
result = resourceService.queryResourceListPaging(loginUser, fullName, tenantCode, type, searchVal, pageNo,
|
||||
return resourceService.queryResourceListPaging(loginUser, fullName, tenantCode, type, searchVal, pageNo,
|
||||
pageSize);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -567,10 +563,7 @@ public class ResourcesController extends BaseController {
|
|||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
return udfFuncService.queryUdfFuncListPaging(loginUser, searchVal, pageNo, pageSize);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -248,14 +248,10 @@ public class SchedulerController extends BaseController {
|
|||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
result = schedulerService.querySchedule(loginUser, projectCode, processDefinitionCode, searchVal, pageNo,
|
||||
return schedulerService.querySchedule(loginUser, projectCode, processDefinitionCode, searchVal, pageNo,
|
||||
pageSize);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -208,10 +208,7 @@ public class TaskDefinitionController extends BaseController {
|
|||
@PathVariable(value = "code") long code,
|
||||
@RequestParam(value = "pageNo") int pageNo,
|
||||
@RequestParam(value = "pageSize") int pageSize) {
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
return taskDefinitionService.queryTaskDefinitionVersions(loginUser, projectCode, code, pageNo, pageSize);
|
||||
}
|
||||
|
||||
|
|
@ -343,10 +340,7 @@ public class TaskDefinitionController extends BaseController {
|
|||
@RequestParam(value = "taskExecuteType", required = false, defaultValue = "BATCH") TaskExecuteType taskExecuteType,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchTaskName = ParameterUtils.handleEscapes(searchTaskName);
|
||||
return taskDefinitionService.queryTaskDefinitionListPaging(loginUser, projectCode,
|
||||
searchTaskName, taskType, taskExecuteType, pageNo, pageSize);
|
||||
|
|
|
|||
|
|
@ -114,12 +114,9 @@ public class TaskInstanceController extends BaseController {
|
|||
@RequestParam(value = "taskExecuteType", required = false, defaultValue = "BATCH") TaskExecuteType taskExecuteType,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
result = taskInstanceService.queryTaskListPaging(
|
||||
return taskInstanceService.queryTaskListPaging(
|
||||
loginUser,
|
||||
projectCode,
|
||||
processInstanceId,
|
||||
|
|
@ -136,7 +133,6 @@ public class TaskInstanceController extends BaseController {
|
|||
taskExecuteType,
|
||||
pageNo,
|
||||
pageSize);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -26,12 +26,14 @@ import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_OS_TENANT_CODE
|
|||
|
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
||||
import org.apache.dolphinscheduler.api.service.TenantService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.dao.entity.Tenant;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
|
@ -81,13 +83,13 @@ public class TenantController extends BaseController {
|
|||
@PostMapping()
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ApiException(CREATE_TENANT_ERROR)
|
||||
public Result createTenant(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "tenantCode") String tenantCode,
|
||||
@RequestParam(value = "queueId") int queueId,
|
||||
@RequestParam(value = "description", required = false) String description) throws Exception {
|
||||
public Result<Tenant> createTenant(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "tenantCode") String tenantCode,
|
||||
@RequestParam(value = "queueId") int queueId,
|
||||
@RequestParam(value = "description", required = false) String description) throws Exception {
|
||||
|
||||
Map<String, Object> result = tenantService.createTenant(loginUser, tenantCode, queueId, description);
|
||||
return returnDataList(result);
|
||||
Tenant tenant = tenantService.createTenant(loginUser, tenantCode, queueId, description);
|
||||
return Result.success(tenant);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -108,18 +110,14 @@ public class TenantController extends BaseController {
|
|||
@GetMapping()
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_TENANT_LIST_PAGING_ERROR)
|
||||
public Result queryTenantlistPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
|
||||
}
|
||||
public Result<PageInfo<Tenant>> queryTenantlistPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
result = tenantService.queryTenantList(loginUser, searchVal, pageNo, pageSize);
|
||||
return result;
|
||||
PageInfo<Tenant> tenantPageInfo = tenantService.queryTenantList(loginUser, searchVal, pageNo, pageSize);
|
||||
return Result.success(tenantPageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -132,9 +130,9 @@ public class TenantController extends BaseController {
|
|||
@GetMapping(value = "/list")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_TENANT_LIST_ERROR)
|
||||
public Result queryTenantlist(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
Map<String, Object> result = tenantService.queryTenantList(loginUser);
|
||||
return returnDataList(result);
|
||||
public Result<List<Tenant>> queryTenantlist(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
List<Tenant> tenants = tenantService.queryTenantList(loginUser);
|
||||
return Result.success(tenants);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -157,14 +155,14 @@ public class TenantController extends BaseController {
|
|||
@PutMapping(value = "/{id}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(UPDATE_TENANT_ERROR)
|
||||
public Result updateTenant(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id,
|
||||
@RequestParam(value = "tenantCode") String tenantCode,
|
||||
@RequestParam(value = "queueId") int queueId,
|
||||
@RequestParam(value = "description", required = false) String description) throws Exception {
|
||||
public Result<Boolean> updateTenant(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id,
|
||||
@RequestParam(value = "tenantCode") String tenantCode,
|
||||
@RequestParam(value = "queueId") int queueId,
|
||||
@RequestParam(value = "description", required = false) String description) throws Exception {
|
||||
|
||||
Map<String, Object> result = tenantService.updateTenant(loginUser, id, tenantCode, queueId, description);
|
||||
return returnDataList(result);
|
||||
tenantService.updateTenant(loginUser, id, tenantCode, queueId, description);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -181,10 +179,10 @@ public class TenantController extends BaseController {
|
|||
@DeleteMapping(value = "/{id}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(DELETE_TENANT_BY_ID_ERROR)
|
||||
public Result deleteTenantById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id) throws Exception {
|
||||
Map<String, Object> result = tenantService.deleteTenantById(loginUser, id);
|
||||
return returnDataList(result);
|
||||
public Result<Boolean> deleteTenantById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id) throws Exception {
|
||||
tenantService.deleteTenantById(loginUser, id);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -201,9 +199,10 @@ public class TenantController extends BaseController {
|
|||
@GetMapping(value = "/verify-code")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(VERIFY_OS_TENANT_CODE_ERROR)
|
||||
public Result verifyTenantCode(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "tenantCode") String tenantCode) {
|
||||
return tenantService.verifyTenantCode(tenantCode);
|
||||
public Result<Boolean> verifyTenantCode(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "tenantCode") String tenantCode) {
|
||||
tenantService.verifyTenantCode(tenantCode);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,14 +140,9 @@ public class UsersController extends BaseController {
|
|||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal) {
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
result = usersService.queryUserList(loginUser, searchVal, pageNo, pageSize);
|
||||
return result;
|
||||
return usersService.queryUserList(loginUser, searchVal, pageNo, pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -69,32 +69,25 @@ public class WorkFlowLineageController extends BaseController {
|
|||
@Operation(summary = "queryLineageByWorkFlowName", description = "QUERY_WORKFLOW_LINEAGE_BY_NAME_NOTES")
|
||||
@GetMapping(value = "/query-by-name")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_WORKFLOW_LINEAGE_ERROR)
|
||||
public Result<List<WorkFlowLineage>> queryWorkFlowLineageByName(@Parameter(hidden = true) @RequestAttribute(value = SESSION_USER) User loginUser,
|
||||
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
|
||||
@RequestParam(value = "workFlowName", required = false) String workFlowName) {
|
||||
try {
|
||||
workFlowName = ParameterUtils.handleEscapes(workFlowName);
|
||||
Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByName(projectCode, workFlowName);
|
||||
return returnDataList(result);
|
||||
} catch (Exception e) {
|
||||
log.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(), e);
|
||||
return error(QUERY_WORKFLOW_LINEAGE_ERROR.getCode(), QUERY_WORKFLOW_LINEAGE_ERROR.getMsg());
|
||||
}
|
||||
workFlowName = ParameterUtils.handleEscapes(workFlowName);
|
||||
List<WorkFlowLineage> workFlowLineages =
|
||||
workFlowLineageService.queryWorkFlowLineageByName(projectCode, workFlowName);
|
||||
return Result.success(workFlowLineages);
|
||||
}
|
||||
|
||||
@Operation(summary = "queryLineageByWorkFlowCode", description = "QUERY_WORKFLOW_LINEAGE_BY_CODE_NOTE")
|
||||
@GetMapping(value = "/{workFlowCode}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_WORKFLOW_LINEAGE_ERROR)
|
||||
public Result<Map<String, Object>> queryWorkFlowLineageByCode(@Parameter(hidden = true) @RequestAttribute(value = SESSION_USER) User loginUser,
|
||||
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
|
||||
@PathVariable(value = "workFlowCode", required = true) long workFlowCode) {
|
||||
try {
|
||||
Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByCode(projectCode, workFlowCode);
|
||||
return returnDataList(result);
|
||||
} catch (Exception e) {
|
||||
log.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(), e);
|
||||
return error(QUERY_WORKFLOW_LINEAGE_ERROR.getCode(), QUERY_WORKFLOW_LINEAGE_ERROR.getMsg());
|
||||
}
|
||||
Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByCode(projectCode, workFlowCode);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "queryWorkFlowList", description = "QUERY_WORKFLOW_LINEAGE_NOTES")
|
||||
|
|
|
|||
|
|
@ -113,14 +113,9 @@ public class WorkerGroupController extends BaseController {
|
|||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize,
|
||||
@RequestParam(value = "searchVal", required = false) String searchVal) {
|
||||
Result result = checkPageParams(pageNo, pageSize);
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
|
||||
}
|
||||
checkPageParams(pageNo, pageSize);
|
||||
searchVal = ParameterUtils.handleEscapes(searchVal);
|
||||
result = workerGroupService.queryAllGroupPaging(loginUser, pageNo, pageSize, searchVal);
|
||||
return result;
|
||||
return workerGroupService.queryAllGroupPaging(loginUser, pageNo, pageSize, searchVal);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ import static org.apache.dolphinscheduler.api.enums.Status.CREATE_ACCESS_TOKEN_E
|
|||
|
||||
import org.apache.dolphinscheduler.api.controller.BaseController;
|
||||
import org.apache.dolphinscheduler.api.dto.CreateTokenRequest;
|
||||
import org.apache.dolphinscheduler.api.dto.CreateTokenResponse;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
||||
import org.apache.dolphinscheduler.api.service.AccessTokenService;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.dao.entity.AccessToken;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -65,12 +65,12 @@ public class AccessTokenV2Controller extends BaseController {
|
|||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@Parameter(name = "createTokenRequest", description = "createTokenRequest", required = true, schema = @Schema(implementation = CreateTokenRequest.class))
|
||||
@ApiException(CREATE_ACCESS_TOKEN_ERROR)
|
||||
public CreateTokenResponse createToken(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
public Result<AccessToken> createToken(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestBody CreateTokenRequest createTokenRequest) {
|
||||
Result result = accessTokenService.createToken(loginUser,
|
||||
AccessToken accessToken = accessTokenService.createToken(loginUser,
|
||||
createTokenRequest.getUserId(),
|
||||
createTokenRequest.getExpireTime(),
|
||||
createTokenRequest.getToken());
|
||||
return new CreateTokenResponse(result);
|
||||
return Result.success(accessToken);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ import org.apache.dolphinscheduler.api.controller.BaseController;
|
|||
import org.apache.dolphinscheduler.api.dto.project.ProjectCreateRequest;
|
||||
import org.apache.dolphinscheduler.api.dto.project.ProjectCreateResponse;
|
||||
import org.apache.dolphinscheduler.api.dto.project.ProjectDeleteResponse;
|
||||
import org.apache.dolphinscheduler.api.dto.project.ProjectListPagingResponse;
|
||||
import org.apache.dolphinscheduler.api.dto.project.ProjectListResponse;
|
||||
import org.apache.dolphinscheduler.api.dto.project.ProjectQueryRequest;
|
||||
import org.apache.dolphinscheduler.api.dto.project.ProjectQueryResponse;
|
||||
|
|
@ -40,8 +39,10 @@ import org.apache.dolphinscheduler.api.dto.project.ProjectUpdateResponse;
|
|||
import org.apache.dolphinscheduler.api.dto.user.UserListResponse;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
||||
import org.apache.dolphinscheduler.api.service.ProjectService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.dao.entity.Project;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
|
||||
|
||||
|
|
@ -150,16 +151,12 @@ public class ProjectV2Controller extends BaseController {
|
|||
@GetMapping(consumes = {"application/json"})
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR)
|
||||
public ProjectListPagingResponse queryProjectListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
public Result<PageInfo<Project>> queryProjectListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
ProjectQueryRequest projectQueryReq) {
|
||||
Result result = checkPageParams(projectQueryReq.getPageNo(), projectQueryReq.getPageSize());
|
||||
if (!result.checkResult()) {
|
||||
return new ProjectListPagingResponse(result);
|
||||
}
|
||||
checkPageParams(projectQueryReq.getPageNo(), projectQueryReq.getPageSize());
|
||||
String searchVal = ParameterUtils.handleEscapes(projectQueryReq.getSearchVal());
|
||||
result = projectService.queryProjectListPaging(loginUser, projectQueryReq.getPageSize(),
|
||||
return projectService.queryProjectListPaging(loginUser, projectQueryReq.getPageSize(),
|
||||
projectQueryReq.getPageNo(), searchVal);
|
||||
return new ProjectListPagingResponse(result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -24,21 +24,20 @@ import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_QUEUE_ERROR;
|
|||
|
||||
import org.apache.dolphinscheduler.api.controller.BaseController;
|
||||
import org.apache.dolphinscheduler.api.dto.queue.QueueCreateRequest;
|
||||
import org.apache.dolphinscheduler.api.dto.queue.QueueCreateResponse;
|
||||
import org.apache.dolphinscheduler.api.dto.queue.QueueListPagingResponse;
|
||||
import org.apache.dolphinscheduler.api.dto.queue.QueueListResponse;
|
||||
import org.apache.dolphinscheduler.api.dto.queue.QueueQueryRequest;
|
||||
import org.apache.dolphinscheduler.api.dto.queue.QueueUpdateRequest;
|
||||
import org.apache.dolphinscheduler.api.dto.queue.QueueUpdateResponse;
|
||||
import org.apache.dolphinscheduler.api.dto.queue.QueueVerifyRequest;
|
||||
import org.apache.dolphinscheduler.api.dto.queue.QueueVerifyResponse;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
||||
import org.apache.dolphinscheduler.api.service.QueueService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.dao.entity.Queue;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
|
@ -78,9 +77,9 @@ public class QueueV2Controller extends BaseController {
|
|||
@GetMapping(value = "/list")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_QUEUE_LIST_ERROR)
|
||||
public QueueListResponse queryList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
Result result = queueService.queryList(loginUser);
|
||||
return new QueueListResponse(result);
|
||||
public Result<List<Queue>> queryList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
|
||||
List<Queue> queues = queueService.queryList(loginUser);
|
||||
return Result.success(queues);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -99,17 +98,14 @@ public class QueueV2Controller extends BaseController {
|
|||
@GetMapping()
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_QUEUE_LIST_ERROR)
|
||||
public QueueListPagingResponse queryQueueListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
public Result<PageInfo<Queue>> queryQueueListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
QueueQueryRequest queueQueryRequest) {
|
||||
Result result = checkPageParams(queueQueryRequest.getPageNo(), queueQueryRequest.getPageSize());
|
||||
if (!result.checkResult()) {
|
||||
return new QueueListPagingResponse(result);
|
||||
}
|
||||
checkPageParams(queueQueryRequest.getPageNo(), queueQueryRequest.getPageSize());
|
||||
|
||||
String searchVal = ParameterUtils.handleEscapes(queueQueryRequest.getSearchVal());
|
||||
result = queueService.queryList(loginUser, searchVal, queueQueryRequest.getPageNo(),
|
||||
PageInfo<Queue> queuePageInfo = queueService.queryList(loginUser, searchVal, queueQueryRequest.getPageNo(),
|
||||
queueQueryRequest.getPageSize());
|
||||
return new QueueListPagingResponse(result);
|
||||
return Result.success(queuePageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -123,11 +119,10 @@ public class QueueV2Controller extends BaseController {
|
|||
@PostMapping(consumes = {"application/json"})
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ApiException(CREATE_QUEUE_ERROR)
|
||||
public QueueCreateResponse createQueue(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestBody QueueCreateRequest queueCreateRequest) {
|
||||
Result result =
|
||||
queueService.createQueue(loginUser, queueCreateRequest.getQueue(), queueCreateRequest.getQueueName());
|
||||
return new QueueCreateResponse(result);
|
||||
public Result<Queue> createQueue(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestBody QueueCreateRequest queueCreateRequest) {
|
||||
return Result.success(
|
||||
queueService.createQueue(loginUser, queueCreateRequest.getQueue(), queueCreateRequest.getQueueName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -145,12 +140,11 @@ public class QueueV2Controller extends BaseController {
|
|||
@PutMapping(value = "/{id}", consumes = {"application/json"})
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ApiException(UPDATE_QUEUE_ERROR)
|
||||
public QueueUpdateResponse updateQueue(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id,
|
||||
@RequestBody QueueUpdateRequest queueUpdateRequest) {
|
||||
Result result = queueService.updateQueue(loginUser, id, queueUpdateRequest.getQueue(),
|
||||
queueUpdateRequest.getQueueName());
|
||||
return new QueueUpdateResponse(result);
|
||||
public Result<Queue> updateQueue(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id,
|
||||
@RequestBody QueueUpdateRequest queueUpdateRequest) {
|
||||
return Result.success(queueService.updateQueue(loginUser, id, queueUpdateRequest.getQueue(),
|
||||
queueUpdateRequest.getQueueName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -164,9 +158,9 @@ public class QueueV2Controller extends BaseController {
|
|||
@PostMapping(value = "/verify", consumes = {"application/json"})
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(VERIFY_QUEUE_ERROR)
|
||||
public QueueVerifyResponse verifyQueue(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestBody QueueVerifyRequest queueVerifyRequest) {
|
||||
Result result = queueService.verifyQueue(queueVerifyRequest.getQueue(), queueVerifyRequest.getQueueName());
|
||||
return new QueueVerifyResponse(result);
|
||||
public Result<Boolean> verifyQueue(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestBody QueueVerifyRequest queueVerifyRequest) {
|
||||
queueService.verifyQueue(queueVerifyRequest.getQueue(), queueVerifyRequest.getQueueName());
|
||||
return Result.success(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COU
|
|||
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_STATES_COUNT_ERROR;
|
||||
|
||||
import org.apache.dolphinscheduler.api.controller.BaseController;
|
||||
import org.apache.dolphinscheduler.api.dto.DefineUserDto;
|
||||
import org.apache.dolphinscheduler.api.dto.TaskCountDto;
|
||||
import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
||||
import org.apache.dolphinscheduler.api.service.DataAnalysisService;
|
||||
|
|
@ -76,7 +78,8 @@ public class StatisticsV2Controller extends BaseController {
|
|||
|
||||
/**
|
||||
* query all workflow states count
|
||||
* @param loginUser login user
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param statisticsStateRequest statisticsStateRequest
|
||||
* @return workflow states count
|
||||
*/
|
||||
|
|
@ -84,16 +87,16 @@ public class StatisticsV2Controller extends BaseController {
|
|||
@GetMapping(value = "/workflows/states/count")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_WORKFLOW_STATES_COUNT_ERROR)
|
||||
public Result queryWorkflowStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
|
||||
Map<String, Object> result =
|
||||
dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest);
|
||||
return returnDataList(result);
|
||||
public Result<TaskCountDto> queryWorkflowStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
|
||||
TaskCountDto taskCountDto = dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest);
|
||||
return Result.success(taskCountDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* query one workflow states count
|
||||
* @param loginUser login user
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param workflowCode workflowCode
|
||||
* @return workflow states count
|
||||
*/
|
||||
|
|
@ -101,16 +104,16 @@ public class StatisticsV2Controller extends BaseController {
|
|||
@GetMapping(value = "/{workflowCode}/states/count")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR)
|
||||
public Result queryOneWorkflowStates(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable("workflowCode") Long workflowCode) {
|
||||
Map<String, Object> result =
|
||||
dataAnalysisService.countOneWorkflowStates(loginUser, workflowCode);
|
||||
return returnDataList(result);
|
||||
public Result<TaskCountDto> queryOneWorkflowStates(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable("workflowCode") Long workflowCode) {
|
||||
TaskCountDto taskCountDto = dataAnalysisService.countOneWorkflowStates(loginUser, workflowCode);
|
||||
return Result.success(taskCountDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* query all task states count
|
||||
* @param loginUser login user
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param statisticsStateRequest statisticsStateRequest
|
||||
* @return tasks states count
|
||||
*/
|
||||
|
|
@ -118,33 +121,33 @@ public class StatisticsV2Controller extends BaseController {
|
|||
@GetMapping(value = "/tasks/states/count")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_TASK_STATES_COUNT_ERROR)
|
||||
public Result queryTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
|
||||
Map<String, Object> result =
|
||||
dataAnalysisService.countTaskStates(loginUser, statisticsStateRequest);
|
||||
return returnDataList(result);
|
||||
public Result<TaskCountDto> queryTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
|
||||
TaskCountDto taskCountDto = dataAnalysisService.countTaskStates(loginUser, statisticsStateRequest);
|
||||
return Result.success(taskCountDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* query one task states count
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param taskCode taskCode
|
||||
* @param taskCode taskCode
|
||||
* @return tasks states count
|
||||
*/
|
||||
@Operation(summary = "queryOneTaskStatesCount", description = "QUERY_ONE_TASK_STATES_COUNT")
|
||||
@GetMapping(value = "/tasks/{taskCode}/states/count")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_ONE_TASK_STATES_COUNT_ERROR)
|
||||
public Result queryOneTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable("taskCode") Long taskCode) {
|
||||
Map<String, Object> result =
|
||||
dataAnalysisService.countOneTaskStates(loginUser, taskCode);
|
||||
return returnDataList(result);
|
||||
public Result<TaskCountDto> queryOneTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable("taskCode") Long taskCode) {
|
||||
TaskCountDto taskCountDto = dataAnalysisService.countOneTaskStates(loginUser, taskCode);
|
||||
return Result.success(taskCountDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* statistics the workflow quantities of certain user
|
||||
* @param loginUser login user
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param statisticsStateRequest statisticsStateRequest
|
||||
* @return workflow count in project code
|
||||
*/
|
||||
|
|
@ -152,47 +155,51 @@ public class StatisticsV2Controller extends BaseController {
|
|||
@GetMapping(value = "/workflows/users/count")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
|
||||
public Result countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
|
||||
public Result<DefineUserDto> countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
|
||||
String projectName = statisticsStateRequest.getProjectName();
|
||||
Long projectCode = statisticsStateRequest.getProjectCode();
|
||||
if (null == projectCode && !StringUtils.isBlank(projectName)) {
|
||||
projectCode = dataAnalysisService.getProjectCodeByName(projectName);
|
||||
}
|
||||
Map<String, Object> result = dataAnalysisService.countDefinitionByUserV2(loginUser, projectCode, null, null);
|
||||
return returnDataList(result);
|
||||
DefineUserDto defineUserDto = dataAnalysisService.countDefinitionByUserV2(loginUser, projectCode, null, null);
|
||||
return Result.success(defineUserDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* statistics the workflow quantities of certain userId
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param userId userId
|
||||
* @param userId userId
|
||||
* @return workflow count in project code
|
||||
*/
|
||||
@Operation(summary = "countDefinitionV2ByUser", description = "COUNT_PROCESS_DEFINITION_V2_BY_USER_NOTES")
|
||||
@GetMapping(value = "/workflows/users/{userId}/count")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
|
||||
public Result countDefinitionByUserId(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable("userId") Integer userId) {
|
||||
Map<String, Object> result = dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, null);
|
||||
return returnDataList(result);
|
||||
public Result<DefineUserDto> countDefinitionByUserId(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable("userId") Integer userId) {
|
||||
DefineUserDto defineUserDto = dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, null);
|
||||
return Result.success(defineUserDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* statistics the workflow quantities of certain userId and releaseState
|
||||
* @param loginUser login user
|
||||
* @param userId userId
|
||||
* @param releaseState releaseState
|
||||
* @return workflow count in project code
|
||||
*/
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param userId userId
|
||||
* @param releaseState releaseState
|
||||
* @return workflow count in project code
|
||||
*/
|
||||
@Operation(summary = "countDefinitionV2ByUser", description = "COUNT_PROCESS_DEFINITION_V2_BY_USER_NOTES")
|
||||
@GetMapping(value = "/workflows/users/{userId}/{releaseState}/count")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
|
||||
public Result countDefinitionByUserState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable("userId") Integer userId,
|
||||
@PathVariable("releaseState") Integer releaseState) {
|
||||
Map<String, Object> result = dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, releaseState);
|
||||
return returnDataList(result);
|
||||
public Result<DefineUserDto> countDefinitionByUserState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable("userId") Integer userId,
|
||||
@PathVariable("releaseState") Integer releaseState) {
|
||||
DefineUserDto defineUserDto =
|
||||
dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, releaseState);
|
||||
return Result.success(defineUserDto);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,11 +24,11 @@ import static org.apache.dolphinscheduler.api.enums.Status.TASK_SAVEPOINT_ERROR;
|
|||
import static org.apache.dolphinscheduler.api.enums.Status.TASK_STOP_ERROR;
|
||||
|
||||
import org.apache.dolphinscheduler.api.controller.BaseController;
|
||||
import org.apache.dolphinscheduler.api.dto.taskInstance.TaskInstanceListPagingResponse;
|
||||
import org.apache.dolphinscheduler.api.dto.taskInstance.TaskInstanceQueryRequest;
|
||||
import org.apache.dolphinscheduler.api.dto.taskInstance.TaskInstanceSuccessResponse;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
||||
import org.apache.dolphinscheduler.api.service.TaskInstanceService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
|
||||
|
|
@ -90,15 +90,13 @@ public class TaskInstanceV2Controller extends BaseController {
|
|||
@GetMapping(consumes = {"application/json"})
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ApiException(QUERY_TASK_LIST_PAGING_ERROR)
|
||||
public TaskInstanceListPagingResponse queryTaskListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
public Result<PageInfo<TaskInstance>> queryTaskListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
|
||||
TaskInstanceQueryRequest taskInstanceQueryReq) {
|
||||
Result result = checkPageParams(taskInstanceQueryReq.getPageNo(), taskInstanceQueryReq.getPageSize());
|
||||
if (!result.checkResult()) {
|
||||
return new TaskInstanceListPagingResponse(result);
|
||||
}
|
||||
checkPageParams(taskInstanceQueryReq.getPageNo(), taskInstanceQueryReq.getPageSize());
|
||||
|
||||
String searchVal = ParameterUtils.handleEscapes(taskInstanceQueryReq.getSearchVal());
|
||||
result = taskInstanceService.queryTaskListPaging(loginUser, projectCode,
|
||||
return taskInstanceService.queryTaskListPaging(loginUser, projectCode,
|
||||
taskInstanceQueryReq.getProcessInstanceId(), taskInstanceQueryReq.getProcessInstanceName(),
|
||||
taskInstanceQueryReq.getProcessDefinitionName(),
|
||||
taskInstanceQueryReq.getTaskName(), taskInstanceQueryReq.getTaskCode(),
|
||||
|
|
@ -107,7 +105,6 @@ public class TaskInstanceV2Controller extends BaseController {
|
|||
taskInstanceQueryReq.getStateType(), taskInstanceQueryReq.getHost(),
|
||||
taskInstanceQueryReq.getTaskExecuteType(), taskInstanceQueryReq.getPageNo(),
|
||||
taskInstanceQueryReq.getPageSize());
|
||||
return new TaskInstanceListPagingResponse(result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -74,14 +74,8 @@ public class WorkflowInstanceV2Controller extends BaseController {
|
|||
@ApiException(Status.QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR)
|
||||
public Result queryWorkflowInstanceListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestBody WorkflowInstanceQueryRequest workflowInstanceQueryRequest) {
|
||||
Result result =
|
||||
checkPageParams(workflowInstanceQueryRequest.getPageNo(), workflowInstanceQueryRequest.getPageSize());
|
||||
if (!result.checkResult()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = processInstanceService.queryProcessInstanceList(loginUser, workflowInstanceQueryRequest);
|
||||
return result;
|
||||
checkPageParams(workflowInstanceQueryRequest.getPageNo(), workflowInstanceQueryRequest.getPageSize());
|
||||
return processInstanceService.queryProcessInstanceList(loginUser, workflowInstanceQueryRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.api.dto.queue;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.dao.entity.Queue;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* queue create response
|
||||
*/
|
||||
@Data
|
||||
public class QueueCreateResponse extends Result {
|
||||
|
||||
private Queue data;
|
||||
|
||||
public QueueCreateResponse(Result result) {
|
||||
super();
|
||||
this.setCode(result.getCode());
|
||||
this.setMsg(result.getMsg());
|
||||
this.setData((Queue) result.getData());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.api.dto.queue;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.dao.entity.Queue;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* queue list paging response
|
||||
*/
|
||||
@Data
|
||||
public class QueueListPagingResponse extends Result {
|
||||
|
||||
private PageInfo<Queue> data;
|
||||
|
||||
public QueueListPagingResponse(Result result) {
|
||||
super();
|
||||
this.setCode(result.getCode());
|
||||
this.setMsg(result.getMsg());
|
||||
this.setData(result.getData());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.api.dto.queue;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
||||
import org.apache.dolphinscheduler.dao.entity.Project;
|
||||
import org.apache.dolphinscheduler.dao.entity.Queue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* queue List response
|
||||
*/
|
||||
@Data
|
||||
public class QueueListResponse extends Result {
|
||||
|
||||
private List<Queue> data;
|
||||
|
||||
public QueueListResponse(Result result) {
|
||||
super();
|
||||
this.setCode(result.getCode());
|
||||
this.setMsg(result.getMsg());
|
||||
this.setData(JSONUtils.toList(JSONUtils.toJsonString(result.getData()), Project.class));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.api.dto.queue;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.dao.entity.Queue;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* queue update response
|
||||
*/
|
||||
@Data
|
||||
public class QueueUpdateResponse extends Result {
|
||||
|
||||
private Queue data;
|
||||
|
||||
public QueueUpdateResponse(Result result) {
|
||||
super();
|
||||
this.setCode(result.getCode());
|
||||
this.setMsg(result.getMsg());
|
||||
this.setData((Queue) result.getData());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.api.dto.queue;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.dao.entity.Queue;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* queue verify response
|
||||
*/
|
||||
@Data
|
||||
public class QueueVerifyResponse extends Result {
|
||||
|
||||
private Queue data;
|
||||
|
||||
public QueueVerifyResponse(Result result) {
|
||||
super();
|
||||
this.setCode(result.getCode());
|
||||
this.setMsg(result.getMsg());
|
||||
this.setData((Queue) result.getData());
|
||||
}
|
||||
}
|
||||
|
|
@ -440,7 +440,7 @@ public enum Status {
|
|||
QUERY_ACCESSTOKEN_LIST_PAGING_ERROR(70012, "query access token list paging error", "分页查询访问token列表错误"),
|
||||
UPDATE_ACCESS_TOKEN_ERROR(70013, "update access token error", "更新访问token错误"),
|
||||
DELETE_ACCESS_TOKEN_ERROR(70014, "delete access token error", "删除访问token错误"),
|
||||
ACCESS_TOKEN_NOT_EXIST(70015, "access token not exist", "访问token不存在"),
|
||||
ACCESS_TOKEN_NOT_EXIST(70015, "access token not exist, tokenId {0}", "访问token不存在, {0}"),
|
||||
QUERY_ACCESSTOKEN_BY_USER_ERROR(70016, "query access token by user error", "查询访问指定用户的token错误"),
|
||||
|
||||
COMMAND_STATE_COUNT_ERROR(80001, "task instance state count error", "查询各状态任务实例数错误"),
|
||||
|
|
|
|||
|
|
@ -36,20 +36,19 @@ import org.springframework.web.method.HandlerMethod;
|
|||
public class ApiExceptionHandler {
|
||||
|
||||
@ExceptionHandler(ServiceException.class)
|
||||
public Result exceptionHandler(ServiceException e, HandlerMethod hm) {
|
||||
log.error("ServiceException: ", e);
|
||||
return new Result(e.getCode(), e.getMessage());
|
||||
public Result<Object> exceptionHandler(ServiceException e, HandlerMethod hm) {
|
||||
log.error("{} Meet a ServiceException: {}", hm.getShortLogMessage(), e.getMessage());
|
||||
return new Result<>(e.getCode(), e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public Result exceptionHandler(Exception e, HandlerMethod hm) {
|
||||
@ExceptionHandler(Throwable.class)
|
||||
public Result<Object> exceptionHandler(Throwable e, HandlerMethod hm) {
|
||||
ApiException ce = hm.getMethodAnnotation(ApiException.class);
|
||||
log.error("Meet en unknown exception: ", e);
|
||||
if (ce == null) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.errorWithArgs(Status.INTERNAL_SERVER_ERROR_ARGS, e.getMessage());
|
||||
}
|
||||
Status st = ce.value();
|
||||
log.error(st.getMsg(), e);
|
||||
return Result.error(st);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dolphinscheduler.api.permission;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -59,11 +58,4 @@ public interface ResourcePermissionCheckService<T> {
|
|||
*/
|
||||
boolean functionDisabled();
|
||||
|
||||
/**
|
||||
* associated with the current user after the resource is created
|
||||
* @param authorizationType
|
||||
* @param ids
|
||||
* @param logger
|
||||
*/
|
||||
void postHandle(Object authorizationType, Integer userId, List<Integer> ids, Logger logger);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,11 +141,6 @@ public class ResourcePermissionCheckServiceImpl
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(Object authorizationType, Integer userId, List<Integer> ids, Logger logger) {
|
||||
logger.debug("no post handle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Object> userOwnedResourceIdsAcquisition(Object authorizationType, Integer userId, Logger logger) {
|
||||
User user = processService.getUserById(userId);
|
||||
|
|
|
|||
|
|
@ -17,10 +17,11 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.dao.entity.AccessToken;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* access token service
|
||||
|
|
@ -36,7 +37,7 @@ public interface AccessTokenService {
|
|||
* @param pageSize page size
|
||||
* @return token list for page number and page size
|
||||
*/
|
||||
Result queryAccessTokenList(User loginUser, String searchVal, Integer pageNo, Integer pageSize);
|
||||
PageInfo<AccessToken> queryAccessTokenList(User loginUser, String searchVal, Integer pageNo, Integer pageSize);
|
||||
|
||||
/**
|
||||
* query access token for specified user
|
||||
|
|
@ -45,7 +46,7 @@ public interface AccessTokenService {
|
|||
* @param userId user id
|
||||
* @return token list for specified user
|
||||
*/
|
||||
Map<String, Object> queryAccessTokenByUser(User loginUser, Integer userId);
|
||||
List<AccessToken> queryAccessTokenByUser(User loginUser, Integer userId);
|
||||
|
||||
/**
|
||||
* create token
|
||||
|
|
@ -55,7 +56,7 @@ public interface AccessTokenService {
|
|||
* @param token token string (if it is absent, it will be automatically generated)
|
||||
* @return create result code
|
||||
*/
|
||||
Result createToken(User loginUser, int userId, String expireTime, String token);
|
||||
AccessToken createToken(User loginUser, int userId, String expireTime, String token);
|
||||
|
||||
/**
|
||||
* generate token
|
||||
|
|
@ -64,7 +65,7 @@ public interface AccessTokenService {
|
|||
* @param expireTime token expire time
|
||||
* @return token string
|
||||
*/
|
||||
Map<String, Object> generateToken(User loginUser, int userId, String expireTime);
|
||||
String generateToken(User loginUser, int userId, String expireTime);
|
||||
|
||||
/**
|
||||
* delete access token
|
||||
|
|
@ -73,7 +74,7 @@ public interface AccessTokenService {
|
|||
* @param id token id
|
||||
* @return delete result code
|
||||
*/
|
||||
Map<String, Object> delAccessTokenById(User loginUser, int id);
|
||||
void deleteAccessTokenById(User loginUser, int id);
|
||||
|
||||
/**
|
||||
* update token by id
|
||||
|
|
@ -84,5 +85,5 @@ public interface AccessTokenService {
|
|||
* @param token token string (if it is absent, it will be automatically generated)
|
||||
* @return updated access token entity
|
||||
*/
|
||||
Map<String, Object> updateToken(User loginUser, int id, int userId, String expireTime, String token);
|
||||
AccessToken updateToken(User loginUser, int id, int userId, String expireTime, String token);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,11 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.dao.entity.AlertGroup;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* alert group service
|
||||
|
|
@ -33,15 +34,15 @@ public interface AlertGroupService {
|
|||
* @param loginUser
|
||||
* @return alert group list
|
||||
*/
|
||||
Map<String, Object> queryAlertgroup(User loginUser);
|
||||
List<AlertGroup> queryAllAlertGroup(User loginUser);
|
||||
|
||||
/**
|
||||
* query normal alert group list
|
||||
*
|
||||
* @param loginUser
|
||||
* @return alert group list
|
||||
* @return alert group list which is is not 2
|
||||
*/
|
||||
Map<String, Object> queryNormalAlertgroup(User loginUser);
|
||||
List<AlertGroup> queryNormalAlertGroups(User loginUser);
|
||||
|
||||
/**
|
||||
* query alert group by id
|
||||
|
|
@ -50,7 +51,7 @@ public interface AlertGroupService {
|
|||
* @param id alert group id
|
||||
* @return one alert group
|
||||
*/
|
||||
Map<String, Object> queryAlertGroupById(User loginUser, Integer id);
|
||||
AlertGroup queryAlertGroupById(User loginUser, Integer id);
|
||||
|
||||
/**
|
||||
* paging query alarm group list
|
||||
|
|
@ -61,7 +62,7 @@ public interface AlertGroupService {
|
|||
* @param pageSize page size
|
||||
* @return alert group list page
|
||||
*/
|
||||
Result listPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize);
|
||||
PageInfo<AlertGroup> listPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize);
|
||||
|
||||
/**
|
||||
* create alert group
|
||||
|
|
@ -70,9 +71,9 @@ public interface AlertGroupService {
|
|||
* @param groupName group name
|
||||
* @param desc description
|
||||
* @param alertInstanceIds alertInstanceIds
|
||||
* @return create result code
|
||||
* @return alertGroup
|
||||
*/
|
||||
Map<String, Object> createAlertgroup(User loginUser, String groupName, String desc, String alertInstanceIds);
|
||||
AlertGroup createAlertGroup(User loginUser, String groupName, String desc, String alertInstanceIds);
|
||||
|
||||
/**
|
||||
* updateProcessInstance alert group
|
||||
|
|
@ -84,8 +85,7 @@ public interface AlertGroupService {
|
|||
* @param alertInstanceIds alertInstanceIds
|
||||
* @return update result code
|
||||
*/
|
||||
Map<String, Object> updateAlertgroup(User loginUser, int id, String groupName, String desc,
|
||||
String alertInstanceIds);
|
||||
AlertGroup updateAlertGroupById(User loginUser, int id, String groupName, String desc, String alertInstanceIds);
|
||||
|
||||
/**
|
||||
* delete alert group by id
|
||||
|
|
@ -94,7 +94,7 @@ public interface AlertGroupService {
|
|||
* @param id alert group id
|
||||
* @return delete result code
|
||||
*/
|
||||
Map<String, Object> delAlertgroupById(User loginUser, int id);
|
||||
void deleteAlertGroupById(User loginUser, int id);
|
||||
|
||||
/**
|
||||
* verify group name exists
|
||||
|
|
|
|||
|
|
@ -17,12 +17,14 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.vo.AlertPluginInstanceVO;
|
||||
import org.apache.dolphinscheduler.common.enums.AlertPluginInstanceType;
|
||||
import org.apache.dolphinscheduler.common.enums.WarningType;
|
||||
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* alert plugin instance service
|
||||
|
|
@ -38,8 +40,11 @@ public interface AlertPluginInstanceService {
|
|||
* @param pluginInstanceParams plugin instance params
|
||||
* @return result
|
||||
*/
|
||||
Map<String, Object> create(User loginUser, int pluginDefineId, String instanceName,
|
||||
AlertPluginInstanceType instanceType, WarningType warningType,
|
||||
AlertPluginInstance create(User loginUser,
|
||||
int pluginDefineId,
|
||||
String instanceName,
|
||||
AlertPluginInstanceType instanceType,
|
||||
WarningType warningType,
|
||||
String pluginInstanceParams);
|
||||
|
||||
/**
|
||||
|
|
@ -50,17 +55,20 @@ public interface AlertPluginInstanceService {
|
|||
* @param pluginInstanceParams plugin instance params
|
||||
* @return result
|
||||
*/
|
||||
Map<String, Object> update(User loginUser, int alertPluginInstanceId, String instanceName,
|
||||
WarningType warningType, String pluginInstanceParams);
|
||||
AlertPluginInstance updateById(User loginUser,
|
||||
int alertPluginInstanceId,
|
||||
String instanceName,
|
||||
WarningType warningType,
|
||||
String pluginInstanceParams);
|
||||
|
||||
/**
|
||||
* delete alert plugin instance
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param id id
|
||||
* @param alertPluginInstanceId id
|
||||
* @return result
|
||||
*/
|
||||
Map<String, Object> delete(User loginUser, int id);
|
||||
void deleteById(User loginUser, int alertPluginInstanceId);
|
||||
|
||||
/**
|
||||
* get alert plugin instance
|
||||
|
|
@ -69,14 +77,14 @@ public interface AlertPluginInstanceService {
|
|||
* @param id get id
|
||||
* @return alert plugin
|
||||
*/
|
||||
Map<String, Object> get(User loginUser, int id);
|
||||
AlertPluginInstance getById(User loginUser, int id);
|
||||
|
||||
/**
|
||||
* queryAll
|
||||
*
|
||||
* @return alert plugins
|
||||
*/
|
||||
Map<String, Object> queryAll();
|
||||
List<AlertPluginInstanceVO> queryAll();
|
||||
|
||||
/**
|
||||
* checkExistPluginInstanceName
|
||||
|
|
@ -93,7 +101,7 @@ public interface AlertPluginInstanceService {
|
|||
* @param pageSize page size
|
||||
* @return plugins
|
||||
*/
|
||||
Result listPaging(User loginUser, String searchVal, int pageNo, int pageSize);
|
||||
PageInfo<AlertPluginInstanceVO> listPaging(User loginUser, String searchVal, int pageNo, int pageSize);
|
||||
|
||||
Result<Void> testSend(int pluginDefineId, String pluginInstanceParams);
|
||||
void testSend(int pluginDefineId, String pluginInstanceParams);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.api.dto.AuditDto;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
|
||||
import org.apache.dolphinscheduler.common.enums.AuditResourceType;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
|
@ -50,8 +51,8 @@ public interface AuditService {
|
|||
* @param pageSize page size
|
||||
* @return audit log string
|
||||
*/
|
||||
Result queryLogListPaging(User loginUser, AuditResourceType resourceType,
|
||||
AuditOperationType operationType, String startTime,
|
||||
String endTime, String userName,
|
||||
Integer pageNo, Integer pageSize);
|
||||
PageInfo<AuditDto> queryLogListPaging(User loginUser, AuditResourceType resourceType,
|
||||
AuditOperationType operationType, String startTime,
|
||||
String endTime, String userName,
|
||||
Integer pageNo, Integer pageSize);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,11 +24,8 @@ import org.apache.dolphinscheduler.common.enums.AuthorizationType;
|
|||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
/**
|
||||
* base service
|
||||
*/
|
||||
|
|
@ -49,16 +46,7 @@ public interface BaseService {
|
|||
* @param result result code
|
||||
* @return true if not administrator, otherwise false
|
||||
*/
|
||||
boolean isNotAdmin(User loginUser, Map<String, Object> result);
|
||||
|
||||
/**
|
||||
* permissionPostHandle
|
||||
* @param authorizationType
|
||||
* @param userId
|
||||
* @param ids
|
||||
* @param logger
|
||||
*/
|
||||
void permissionPostHandle(AuthorizationType authorizationType, Integer userId, List<Integer> ids, Logger logger);
|
||||
boolean isNotAdmin(User loginUser);
|
||||
|
||||
/**
|
||||
* put message to map
|
||||
|
|
|
|||
|
|
@ -17,10 +17,12 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.api.dto.ClusterDto;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.dao.entity.Cluster;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* cluster service
|
||||
|
|
@ -34,22 +36,23 @@ public interface ClusterService {
|
|||
* @param name cluster name
|
||||
* @param config cluster config
|
||||
* @param desc cluster desc
|
||||
* @return cluster code
|
||||
*/
|
||||
Map<String, Object> createCluster(User loginUser, String name, String config, String desc);
|
||||
Long createCluster(User loginUser, String name, String config, String desc);
|
||||
|
||||
/**
|
||||
* query cluster
|
||||
*
|
||||
* @param name cluster name
|
||||
*/
|
||||
Map<String, Object> queryClusterByName(String name);
|
||||
ClusterDto queryClusterByName(String name);
|
||||
|
||||
/**
|
||||
* query cluster
|
||||
*
|
||||
* @param code cluster code
|
||||
*/
|
||||
Map<String, Object> queryClusterByCode(Long code);
|
||||
ClusterDto queryClusterByCode(Long code);
|
||||
|
||||
/**
|
||||
* delete cluster
|
||||
|
|
@ -57,7 +60,7 @@ public interface ClusterService {
|
|||
* @param loginUser login user
|
||||
* @param code cluster code
|
||||
*/
|
||||
Map<String, Object> deleteClusterByCode(User loginUser, Long code);
|
||||
void deleteClusterByCode(User loginUser, Long code);
|
||||
|
||||
/**
|
||||
* update cluster
|
||||
|
|
@ -68,7 +71,7 @@ public interface ClusterService {
|
|||
* @param config cluster config
|
||||
* @param desc cluster desc
|
||||
*/
|
||||
Map<String, Object> updateClusterByCode(User loginUser, Long code, String name, String config, String desc);
|
||||
Cluster updateClusterByCode(User loginUser, Long code, String name, String config, String desc);
|
||||
|
||||
/**
|
||||
* query cluster paging
|
||||
|
|
@ -78,14 +81,14 @@ public interface ClusterService {
|
|||
* @param pageSize page size
|
||||
* @return cluster list page
|
||||
*/
|
||||
Result queryClusterListPaging(Integer pageNo, Integer pageSize, String searchVal);
|
||||
PageInfo<ClusterDto> queryClusterListPaging(Integer pageNo, Integer pageSize, String searchVal);
|
||||
|
||||
/**
|
||||
* query all cluster
|
||||
*
|
||||
* @return all cluster list
|
||||
*/
|
||||
Map<String, Object> queryAllClusterList();
|
||||
List<ClusterDto> queryAllClusterList();
|
||||
|
||||
/**
|
||||
* verify cluster name
|
||||
|
|
@ -93,6 +96,6 @@ public interface ClusterService {
|
|||
* @param clusterName cluster name
|
||||
* @return true if the cluster name not exists, otherwise return false
|
||||
*/
|
||||
Map<String, Object> verifyCluster(String clusterName);
|
||||
void verifyCluster(String clusterName);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.api.dto.CommandStateCount;
|
||||
import org.apache.dolphinscheduler.api.dto.DefineUserDto;
|
||||
import org.apache.dolphinscheduler.api.dto.TaskCountDto;
|
||||
import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
|
||||
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
|
@ -41,7 +44,7 @@ public interface DataAnalysisService {
|
|||
* @param endDate end date
|
||||
* @return task state count data
|
||||
*/
|
||||
Map<String, Object> countTaskStateByProject(User loginUser, long projectCode, String startDate, String endDate);
|
||||
TaskCountDto countTaskStateByProject(User loginUser, long projectCode, String startDate, String endDate);
|
||||
|
||||
/**
|
||||
* statistical process instance status data
|
||||
|
|
@ -52,8 +55,8 @@ public interface DataAnalysisService {
|
|||
* @param endDate end date
|
||||
* @return process instance state count data
|
||||
*/
|
||||
Map<String, Object> countProcessInstanceStateByProject(User loginUser, long projectCode, String startDate,
|
||||
String endDate);
|
||||
TaskCountDto countProcessInstanceStateByProject(User loginUser, long projectCode, String startDate,
|
||||
String endDate);
|
||||
|
||||
/**
|
||||
* statistics the process definition quantities of a certain person
|
||||
|
|
@ -64,7 +67,7 @@ public interface DataAnalysisService {
|
|||
* @param projectCode project code
|
||||
* @return workflow count data
|
||||
*/
|
||||
Map<String, Object> countDefinitionByUser(User loginUser, long projectCode);
|
||||
DefineUserDto countDefinitionByUser(User loginUser, long projectCode);
|
||||
/**
|
||||
* statistics the workflow quantities of certain user
|
||||
* <p>
|
||||
|
|
@ -76,7 +79,7 @@ public interface DataAnalysisService {
|
|||
* @param releaseState releaseState
|
||||
* @return workflow count data
|
||||
*/
|
||||
Map<String, Object> countDefinitionByUserV2(User loginUser, Long projectCode, Integer userId, Integer releaseState);
|
||||
DefineUserDto countDefinitionByUserV2(User loginUser, Long projectCode, Integer userId, Integer releaseState);
|
||||
|
||||
/**
|
||||
* statistical command status data
|
||||
|
|
@ -84,7 +87,7 @@ public interface DataAnalysisService {
|
|||
* @param loginUser login user
|
||||
* @return command state count data
|
||||
*/
|
||||
Map<String, Object> countCommandState(User loginUser);
|
||||
List<CommandStateCount> countCommandState(User loginUser);
|
||||
|
||||
/**
|
||||
* count queue state
|
||||
|
|
@ -92,7 +95,7 @@ public interface DataAnalysisService {
|
|||
* @param loginUser login user
|
||||
* @return queue state count data
|
||||
*/
|
||||
Map<String, Object> countQueueState(User loginUser);
|
||||
Map<String, Integer> countQueueState(User loginUser);
|
||||
|
||||
/**
|
||||
* Statistics task instance group by given project codes list
|
||||
|
|
@ -121,8 +124,8 @@ public interface DataAnalysisService {
|
|||
* @param statisticsStateRequest statisticsStateRequest
|
||||
* @return workflow states count
|
||||
*/
|
||||
Map<String, Object> countWorkflowStates(User loginUser,
|
||||
StatisticsStateRequest statisticsStateRequest);
|
||||
TaskCountDto countWorkflowStates(User loginUser,
|
||||
StatisticsStateRequest statisticsStateRequest);
|
||||
|
||||
/**
|
||||
* query one workflow states count
|
||||
|
|
@ -130,7 +133,7 @@ public interface DataAnalysisService {
|
|||
* @param workflowCode workflowCode
|
||||
* @return workflow states count
|
||||
*/
|
||||
Map<String, Object> countOneWorkflowStates(User loginUser, Long workflowCode);
|
||||
TaskCountDto countOneWorkflowStates(User loginUser, Long workflowCode);
|
||||
|
||||
/**
|
||||
* query all task states count
|
||||
|
|
@ -138,7 +141,7 @@ public interface DataAnalysisService {
|
|||
* @param statisticsStateRequest statisticsStateRequest
|
||||
* @return tasks states count
|
||||
*/
|
||||
Map<String, Object> countTaskStates(User loginUser, StatisticsStateRequest statisticsStateRequest);
|
||||
TaskCountDto countTaskStates(User loginUser, StatisticsStateRequest statisticsStateRequest);
|
||||
|
||||
/**
|
||||
* query one task states count
|
||||
|
|
@ -146,7 +149,7 @@ public interface DataAnalysisService {
|
|||
* @param taskCode taskCode
|
||||
* @return tasks states count
|
||||
*/
|
||||
Map<String, Object> countOneTaskStates(User loginUser, Long taskCode);
|
||||
TaskCountDto countOneTaskStates(User loginUser, Long taskCode);
|
||||
|
||||
Long getProjectCodeByName(String projectName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.dao.entity.DataSource;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.BaseDataSourceParamDTO;
|
||||
|
|
@ -40,17 +39,16 @@ public interface DataSourceService {
|
|||
* @param datasourceParam datasource parameter
|
||||
* @return create result code
|
||||
*/
|
||||
Result<Object> createDataSource(User loginUser, BaseDataSourceParamDTO datasourceParam);
|
||||
DataSource createDataSource(User loginUser, BaseDataSourceParamDTO datasourceParam);
|
||||
|
||||
/**
|
||||
* updateProcessInstance datasource
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param id data source id
|
||||
* @param dataSourceParam data source params
|
||||
* @return update result code
|
||||
*/
|
||||
Result<Object> updateDataSource(int id, User loginUser, BaseDataSourceParamDTO dataSourceParam);
|
||||
DataSource updateDataSource(User loginUser, BaseDataSourceParamDTO dataSourceParam);
|
||||
|
||||
/**
|
||||
* updateProcessInstance datasource
|
||||
|
|
@ -86,7 +84,7 @@ public interface DataSourceService {
|
|||
* @param name datasource name
|
||||
* @return true if data datasource not exists, otherwise return false
|
||||
*/
|
||||
Result<Object> verifyDataSourceName(String name);
|
||||
void verifyDataSourceName(String name);
|
||||
|
||||
/**
|
||||
* check connection
|
||||
|
|
@ -95,7 +93,7 @@ public interface DataSourceService {
|
|||
* @param parameter data source parameters
|
||||
* @return true if connect successfully, otherwise false
|
||||
*/
|
||||
Result<Object> checkConnection(DbType type, ConnectionParam parameter);
|
||||
void checkConnection(DbType type, ConnectionParam parameter);
|
||||
|
||||
/**
|
||||
* test connection
|
||||
|
|
@ -103,7 +101,7 @@ public interface DataSourceService {
|
|||
* @param id datasource id
|
||||
* @return connect result code
|
||||
*/
|
||||
Result<Object> connectionTest(int id);
|
||||
void connectionTest(int id);
|
||||
|
||||
/**
|
||||
* delete datasource
|
||||
|
|
@ -112,7 +110,7 @@ public interface DataSourceService {
|
|||
* @param datasourceId data source id
|
||||
* @return delete result code
|
||||
*/
|
||||
Result<Object> delete(User loginUser, int datasourceId);
|
||||
void delete(User loginUser, int datasourceId);
|
||||
|
||||
/**
|
||||
* unauthorized datasource
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.dao.entity.DqExecuteResult;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
||||
/**
|
||||
|
|
@ -25,11 +26,11 @@ import org.apache.dolphinscheduler.dao.entity.User;
|
|||
*/
|
||||
public interface DqExecuteResultService {
|
||||
|
||||
Result queryResultListPaging(User loginUser,
|
||||
String searchVal,
|
||||
Integer state,
|
||||
Integer ruleType,
|
||||
String startTime,
|
||||
String endTime,
|
||||
Integer pageNo, Integer pageSize);
|
||||
PageInfo<DqExecuteResult> queryResultListPaging(User loginUser,
|
||||
String searchVal,
|
||||
Integer state,
|
||||
Integer ruleType,
|
||||
String startTime,
|
||||
String endTime,
|
||||
Integer pageNo, Integer pageSize);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,26 +17,28 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.dao.entity.DqRule;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.spi.params.base.ParamsOptions;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* DqsRuleService
|
||||
*/
|
||||
public interface DqRuleService {
|
||||
|
||||
Map<String, Object> getRuleFormCreateJsonById(int id);
|
||||
String getRuleFormCreateJsonById(int id);
|
||||
|
||||
Map<String, Object> queryAllRuleList();
|
||||
List<DqRule> queryAllRuleList();
|
||||
|
||||
Result queryRuleListPaging(User loginUser,
|
||||
String searchVal,
|
||||
Integer ruleType,
|
||||
String startTime,
|
||||
String endTime,
|
||||
Integer pageNo, Integer pageSize);
|
||||
PageInfo<DqRule> queryRuleListPaging(User loginUser,
|
||||
String searchVal,
|
||||
Integer ruleType,
|
||||
String startTime,
|
||||
String endTime,
|
||||
Integer pageNo, Integer pageSize);
|
||||
|
||||
Map<String, Object> getDatasourceOptionsById(int datasourceId);
|
||||
List<ParamsOptions> getDatasourceOptionsById(int datasourceId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.dao.entity.Environment;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
||||
import java.util.Map;
|
||||
|
|
@ -36,7 +37,7 @@ public interface EnvironmentService {
|
|||
* @param desc environment desc
|
||||
* @param workerGroups worker groups
|
||||
*/
|
||||
Map<String, Object> createEnvironment(User loginUser, String name, String config, String desc, String workerGroups);
|
||||
Long createEnvironment(User loginUser, String name, String config, String desc, String workerGroups);
|
||||
|
||||
/**
|
||||
* query environment
|
||||
|
|
@ -70,8 +71,8 @@ public interface EnvironmentService {
|
|||
* @param desc environment desc
|
||||
* @param workerGroups worker groups
|
||||
*/
|
||||
Map<String, Object> updateEnvironmentByCode(User loginUser, Long code, String name, String config, String desc,
|
||||
String workerGroups);
|
||||
Environment updateEnvironmentByCode(User loginUser, Long code, String name, String config, String desc,
|
||||
String workerGroups);
|
||||
|
||||
/**
|
||||
* query environment paging
|
||||
|
|
|
|||
|
|
@ -164,12 +164,12 @@ public interface ExecutorService {
|
|||
* @param startParams the global param values which pass to new process instance
|
||||
* @return execute process instance code
|
||||
*/
|
||||
Map<String, Object> execStreamTaskInstance(User loginUser, long projectCode,
|
||||
long taskDefinitionCode, int taskDefinitionVersion,
|
||||
int warningGroupId,
|
||||
String workerGroup,
|
||||
String tenantCode,
|
||||
Long environmentCode,
|
||||
Map<String, String> startParams,
|
||||
int dryRun);
|
||||
void execStreamTaskInstance(User loginUser, long projectCode,
|
||||
long taskDefinitionCode, int taskDefinitionVersion,
|
||||
int warningGroupId,
|
||||
String workerGroup,
|
||||
String tenantCode,
|
||||
Long environmentCode,
|
||||
Map<String, String> startParams,
|
||||
int dryRun);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@ import org.apache.dolphinscheduler.api.utils.Result;
|
|||
import org.apache.dolphinscheduler.dao.entity.ResponseTaskLog;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* logger service
|
||||
*/
|
||||
|
|
@ -58,7 +56,7 @@ public interface LoggerService {
|
|||
* @param limit limit
|
||||
* @return log string data
|
||||
*/
|
||||
Map<String, Object> queryLog(User loginUser, long projectCode, int taskInstId, int skipLineNum, int limit);
|
||||
String queryLog(User loginUser, long projectCode, int taskInstId, int skipLineNum, int limit);
|
||||
|
||||
/**
|
||||
* get log bytes
|
||||
|
|
|
|||
|
|
@ -18,10 +18,11 @@
|
|||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.common.model.Server;
|
||||
import org.apache.dolphinscheduler.common.model.WorkerServerModel;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMetrics;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* monitor service
|
||||
|
|
@ -34,7 +35,7 @@ public interface MonitorService {
|
|||
* @param loginUser login user
|
||||
* @return data base state
|
||||
*/
|
||||
Map<String, Object> queryDatabaseState(User loginUser);
|
||||
List<DatabaseMetrics> queryDatabaseState(User loginUser);
|
||||
|
||||
/**
|
||||
* query master list
|
||||
|
|
@ -42,7 +43,7 @@ public interface MonitorService {
|
|||
* @param loginUser login user
|
||||
* @return master information list
|
||||
*/
|
||||
Map<String, Object> queryMaster(User loginUser);
|
||||
List<Server> queryMaster(User loginUser);
|
||||
|
||||
/**
|
||||
* query worker list
|
||||
|
|
@ -50,7 +51,7 @@ public interface MonitorService {
|
|||
* @param loginUser login user
|
||||
* @return worker information list
|
||||
*/
|
||||
Map<String, Object> queryWorker(User loginUser);
|
||||
List<WorkerServerModel> queryWorker(User loginUser);
|
||||
|
||||
List<Server> getServerListFromRegistry(boolean isMaster);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ public interface ProjectService {
|
|||
* @param perm String
|
||||
* @return true if the login user have permission to see the project
|
||||
*/
|
||||
@Deprecated
|
||||
Map<String, Object> checkProjectAndAuth(User loginUser, Project project, long projectCode, String perm);
|
||||
|
||||
void checkProjectAndAuthThrowException(User loginUser, Project project, String permission) throws ServiceException;
|
||||
|
|
@ -82,12 +83,19 @@ public interface ProjectService {
|
|||
* @param permission String
|
||||
* @return true if the login user have permission to the project
|
||||
*/
|
||||
@Deprecated
|
||||
boolean hasProjectAndPerm(User loginUser, Project project, Result result, String permission);
|
||||
|
||||
@Deprecated
|
||||
boolean hasProjectAndWritePerm(User loginUser, Project project, Result result);
|
||||
|
||||
@Deprecated
|
||||
boolean hasProjectAndWritePerm(User loginUser, Project project, Map<String, Object> result);
|
||||
|
||||
void checkHasProjectWritePermissionThrowException(User loginUser, long projectCode);
|
||||
|
||||
void checkHasProjectWritePermissionThrowException(User loginUser, Project project);
|
||||
|
||||
/**
|
||||
* admin can view all projects
|
||||
*
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.dao.entity.Queue;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* queue service
|
||||
|
|
@ -34,58 +34,57 @@ public interface QueueService {
|
|||
* @param loginUser login user
|
||||
* @return queue list
|
||||
*/
|
||||
Result queryList(User loginUser);
|
||||
List<Queue> queryList(User loginUser);
|
||||
|
||||
/**
|
||||
* query queue list paging
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param pageNo page number
|
||||
* @param pageNo page number
|
||||
* @param searchVal search value
|
||||
* @param pageSize page size
|
||||
* @param pageSize page size
|
||||
* @return queue list
|
||||
*/
|
||||
Result queryList(User loginUser, String searchVal, Integer pageNo, Integer pageSize);
|
||||
PageInfo<Queue> queryList(User loginUser, String searchVal, Integer pageNo, Integer pageSize);
|
||||
|
||||
/**
|
||||
* create queue
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param queue queue
|
||||
* @param queue queue
|
||||
* @param queueName queue name
|
||||
* @return create result
|
||||
*/
|
||||
Result createQueue(User loginUser, String queue, String queueName);
|
||||
Queue createQueue(User loginUser, String queue, String queueName);
|
||||
|
||||
/**
|
||||
* update queue
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param queue queue
|
||||
* @param id queue id
|
||||
* @param queue queue
|
||||
* @param id queue id
|
||||
* @param queueName queue name
|
||||
* @return update result code
|
||||
*/
|
||||
Result updateQueue(User loginUser, int id, String queue, String queueName);
|
||||
Queue updateQueue(User loginUser, int id, String queue, String queueName);
|
||||
|
||||
/**
|
||||
* delete queue
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param id queue id
|
||||
* @param id queue id
|
||||
* @return delete result code
|
||||
* @throws Exception exception
|
||||
*/
|
||||
Map<String, Object> deleteQueueById(User loginUser, int id) throws Exception;
|
||||
void deleteQueueById(User loginUser, int id) throws Exception;
|
||||
|
||||
/**
|
||||
* verify queue and queueName
|
||||
*
|
||||
* @param queue queue
|
||||
* @param queueName queue name
|
||||
* @return true if the queue name not exists, otherwise return false
|
||||
*/
|
||||
Result<Object> verifyQueue(String queue, String queueName);
|
||||
void verifyQueue(String queue, String queueName);
|
||||
|
||||
/**
|
||||
* Make sure queue with given name exists, and create the queue if not exists
|
||||
|
|
|
|||
|
|
@ -17,10 +17,11 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.dao.entity.Tenant;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -31,52 +32,54 @@ public interface TenantService {
|
|||
/**
|
||||
* create tenant
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param loginUser login user
|
||||
* @param tenantCode tenant code
|
||||
* @param queueId queue id
|
||||
* @param desc description
|
||||
* @param queueId queue id
|
||||
* @param desc description
|
||||
* @return create result code
|
||||
* @throws Exception exception
|
||||
*/
|
||||
Map<String, Object> createTenant(User loginUser,
|
||||
String tenantCode,
|
||||
int queueId,
|
||||
String desc) throws Exception;
|
||||
Tenant createTenant(User loginUser,
|
||||
String tenantCode,
|
||||
int queueId,
|
||||
String desc) throws Exception;
|
||||
|
||||
/**
|
||||
* query tenant list paging
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param searchVal search value
|
||||
* @param pageNo page number
|
||||
* @param pageSize page size
|
||||
* @param pageNo page number
|
||||
* @param pageSize page size
|
||||
* @return tenant list page
|
||||
*/
|
||||
Result queryTenantList(User loginUser, String searchVal, Integer pageNo, Integer pageSize);
|
||||
PageInfo<Tenant> queryTenantList(User loginUser, String searchVal, Integer pageNo, Integer pageSize);
|
||||
|
||||
/**
|
||||
* updateProcessInstance tenant
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param id tennat id
|
||||
* @param loginUser login user
|
||||
* @param id tennat id
|
||||
* @param tenantCode tennat code
|
||||
* @param queueId queue id
|
||||
* @param desc description
|
||||
* @param queueId queue id
|
||||
* @param desc description
|
||||
* @return update result code
|
||||
* @throws Exception exception
|
||||
*/
|
||||
Map<String, Object> updateTenant(User loginUser, int id, String tenantCode, int queueId,
|
||||
String desc) throws Exception;
|
||||
void updateTenant(User loginUser,
|
||||
int id, String tenantCode,
|
||||
int queueId,
|
||||
String desc) throws Exception;
|
||||
|
||||
/**
|
||||
* delete tenant
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param id tenant id
|
||||
* @param id tenant id
|
||||
* @return delete result code
|
||||
* @throws Exception exception
|
||||
*/
|
||||
Map<String, Object> deleteTenantById(User loginUser, int id) throws Exception;
|
||||
void deleteTenantById(User loginUser, int id) throws Exception;
|
||||
|
||||
/**
|
||||
* query tenant list
|
||||
|
|
@ -84,7 +87,7 @@ public interface TenantService {
|
|||
* @param loginUser login user
|
||||
* @return tenant list
|
||||
*/
|
||||
Map<String, Object> queryTenantList(User loginUser);
|
||||
List<Tenant> queryTenantList(User loginUser);
|
||||
|
||||
/**
|
||||
* verify tenant code
|
||||
|
|
@ -92,7 +95,7 @@ public interface TenantService {
|
|||
* @param tenantCode tenant code
|
||||
* @return true if tenant code can user, otherwise return false
|
||||
*/
|
||||
Result verifyTenantCode(String tenantCode);
|
||||
void verifyTenantCode(String tenantCode);
|
||||
|
||||
/**
|
||||
* query tenant by tenant code
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@
|
|||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.dao.entity.TaskMainInfo;
|
||||
import org.apache.dolphinscheduler.dao.entity.WorkFlowLineage;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
|
@ -28,7 +30,7 @@ import java.util.Set;
|
|||
*/
|
||||
public interface WorkFlowLineageService {
|
||||
|
||||
Map<String, Object> queryWorkFlowLineageByName(long projectCode, String workFlowName);
|
||||
List<WorkFlowLineage> queryWorkFlowLineageByName(long projectCode, String workFlowName);
|
||||
|
||||
Map<String, Object> queryWorkFlowLineageByCode(long projectCode, long workFlowCode);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,10 +22,9 @@ import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationCon
|
|||
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.ACCESS_TOKEN_UPDATE;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
|
||||
import org.apache.dolphinscheduler.api.service.AccessTokenService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
import org.apache.dolphinscheduler.common.utils.DateUtils;
|
||||
|
|
@ -37,9 +36,7 @@ import org.apache.dolphinscheduler.dao.mapper.AccessTokenMapper;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
|
@ -64,13 +61,13 @@ public class AccessTokenServiceImpl extends BaseServiceImpl implements AccessTok
|
|||
*
|
||||
* @param loginUser login user
|
||||
* @param searchVal search value
|
||||
* @param pageNo page number
|
||||
* @param pageSize page size
|
||||
* @param pageNo page number
|
||||
* @param pageSize page size
|
||||
* @return token list for page number and page size
|
||||
*/
|
||||
@Override
|
||||
public Result queryAccessTokenList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) {
|
||||
Result result = new Result();
|
||||
public PageInfo<AccessToken> queryAccessTokenList(User loginUser, String searchVal, Integer pageNo,
|
||||
Integer pageSize) {
|
||||
PageInfo<AccessToken> pageInfo = new PageInfo<>(pageNo, pageSize);
|
||||
Page<AccessToken> page = new Page<>(pageNo, pageSize);
|
||||
int userId = loginUser.getId();
|
||||
|
|
@ -80,33 +77,26 @@ public class AccessTokenServiceImpl extends BaseServiceImpl implements AccessTok
|
|||
IPage<AccessToken> accessTokenList = accessTokenMapper.selectAccessTokenPage(page, searchVal, userId);
|
||||
pageInfo.setTotal((int) accessTokenList.getTotal());
|
||||
pageInfo.setTotalList(accessTokenList.getRecords());
|
||||
result.setData(pageInfo);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* query access token for specified user
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param userId user id
|
||||
* @param userId user id
|
||||
* @return token list for specified user
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> queryAccessTokenByUser(User loginUser, Integer userId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put(Constants.STATUS, false);
|
||||
public List<AccessToken> queryAccessTokenByUser(User loginUser, Integer userId) {
|
||||
// no permission
|
||||
if (loginUser.getUserType().equals(UserType.GENERAL_USER) && loginUser.getId() != userId) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
userId = loginUser.getUserType().equals(UserType.ADMIN_USER) ? 0 : userId;
|
||||
// query access token for specified user
|
||||
List<AccessToken> accessTokenList = this.accessTokenMapper.queryAccessTokenByUser(userId);
|
||||
result.put(Constants.DATA_LIST, accessTokenList);
|
||||
this.putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return accessTokenList;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -120,22 +110,18 @@ public class AccessTokenServiceImpl extends BaseServiceImpl implements AccessTok
|
|||
*/
|
||||
@SuppressWarnings("checkstyle:WhitespaceAround")
|
||||
@Override
|
||||
public Result createToken(User loginUser, int userId, String expireTime, String token) {
|
||||
Result result = new Result();
|
||||
public AccessToken createToken(User loginUser, int userId, String expireTime, String token) {
|
||||
|
||||
// 1. check permission
|
||||
if (!(canOperatorPermissions(loginUser, null, AuthorizationType.ACCESS_TOKEN, ACCESS_TOKEN_CREATE)
|
||||
|| loginUser.getId() == userId)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
// 2. check if user is existed
|
||||
if (userId <= 0) {
|
||||
String errorMsg = "User id should not less than or equals to 0.";
|
||||
log.error(errorMsg);
|
||||
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, errorMsg);
|
||||
return result;
|
||||
throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR,
|
||||
"User id: " + userId + " should not less than or equals to 0.");
|
||||
}
|
||||
|
||||
// 3. generate access token if absent
|
||||
|
|
@ -154,94 +140,75 @@ public class AccessTokenServiceImpl extends BaseServiceImpl implements AccessTok
|
|||
int insert = accessTokenMapper.insert(accessToken);
|
||||
|
||||
if (insert > 0) {
|
||||
result.setData(accessToken);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
} else {
|
||||
putMsg(result, Status.CREATE_ACCESS_TOKEN_ERROR);
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
return result;
|
||||
throw new ServiceException(Status.CREATE_ACCESS_TOKEN_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* generate token
|
||||
*
|
||||
* @param loginUser
|
||||
* @param userId token for user
|
||||
* @param userId token for user
|
||||
* @param expireTime token expire time
|
||||
* @return token string
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> generateToken(User loginUser, int userId, String expireTime) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
String token = EncryptionUtils.getMd5(userId + expireTime + System.currentTimeMillis());
|
||||
result.put(Constants.DATA_LIST, token);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
public String generateToken(User loginUser, int userId, String expireTime) {
|
||||
return EncryptionUtils.getMd5(userId + expireTime + System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* delete access token
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param id token id
|
||||
* @param id token id
|
||||
* @return delete result code
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> delAccessTokenById(User loginUser, int id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public void deleteAccessTokenById(User loginUser, int id) {
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.ACCESS_TOKEN, ACCESS_TOKEN_DELETE)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
AccessToken accessToken = accessTokenMapper.selectById(id);
|
||||
if (accessToken == null) {
|
||||
log.error("Access token does not exist, accessTokenId:{}.", id);
|
||||
putMsg(result, Status.ACCESS_TOKEN_NOT_EXIST);
|
||||
return result;
|
||||
throw new ServiceException(Status.ACCESS_TOKEN_NOT_EXIST, id);
|
||||
}
|
||||
|
||||
// admin can operate all, non-admin can operate their own
|
||||
if (accessToken.getUserId() != loginUser.getId() && !loginUser.getUserType().equals(UserType.ADMIN_USER)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
accessTokenMapper.deleteById(id);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* update token by id
|
||||
*
|
||||
* @param id token id
|
||||
* @param userId token for user
|
||||
* @param id token id
|
||||
* @param userId token for user
|
||||
* @param expireTime token expire time
|
||||
* @param token token string (if it is absent, it will be automatically generated)
|
||||
* @param token token string (if it is absent, it will be automatically generated)
|
||||
* @return updated access token entity
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> updateToken(User loginUser, int id, int userId, String expireTime, String token) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public AccessToken updateToken(User loginUser, int id, int userId, String expireTime, String token) {
|
||||
|
||||
// 1. check permission
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.ACCESS_TOKEN, ACCESS_TOKEN_UPDATE)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
// 2. check if token is existed
|
||||
AccessToken accessToken = accessTokenMapper.selectById(id);
|
||||
if (accessToken == null) {
|
||||
log.error("Access token does not exist, accessTokenId:{}.", id);
|
||||
putMsg(result, Status.ACCESS_TOKEN_NOT_EXIST);
|
||||
return result;
|
||||
throw new ServiceException(Status.ACCESS_TOKEN_NOT_EXIST, id);
|
||||
}
|
||||
// admin can operate all, non-admin can operate their own
|
||||
if (accessToken.getUserId() != loginUser.getId() && !loginUser.getUserType().equals(UserType.ADMIN_USER)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
// 3. generate access token if absent
|
||||
|
|
@ -255,10 +222,10 @@ public class AccessTokenServiceImpl extends BaseServiceImpl implements AccessTok
|
|||
accessToken.setToken(token);
|
||||
accessToken.setUpdateTime(new Date());
|
||||
|
||||
accessTokenMapper.updateById(accessToken);
|
||||
|
||||
result.put(Constants.DATA_LIST, accessToken);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
int i = accessTokenMapper.updateById(accessToken);
|
||||
if (i <= 0) {
|
||||
throw new ServiceException(Status.ACCESS_TOKEN_NOT_EXIST, id);
|
||||
}
|
||||
return accessToken;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,10 +23,9 @@ import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationCon
|
|||
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.ALERT_GROUP_VIEW;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
|
||||
import org.apache.dolphinscheduler.api.service.AlertGroupService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
import org.apache.dolphinscheduler.dao.entity.AlertGroup;
|
||||
|
|
@ -71,74 +70,47 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup
|
|||
* @return alert group list
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> queryAlertgroup(User loginUser) {
|
||||
HashMap<String, Object> result = new HashMap<>();
|
||||
List<AlertGroup> alertGroups;
|
||||
public List<AlertGroup> queryAllAlertGroup(User loginUser) {
|
||||
if (loginUser.getUserType().equals(UserType.ADMIN_USER)) {
|
||||
alertGroups = alertGroupMapper.queryAllGroupList();
|
||||
} else {
|
||||
Set<Integer> ids = resourcePermissionCheckService
|
||||
.userOwnedResourceIdsAcquisition(AuthorizationType.ALERT_GROUP, loginUser.getId(), log);
|
||||
if (ids.isEmpty()) {
|
||||
result.put(Constants.DATA_LIST, Collections.emptyList());
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
alertGroups = alertGroupMapper.selectBatchIds(ids);
|
||||
return alertGroupMapper.queryAllGroupList();
|
||||
}
|
||||
result.put(Constants.DATA_LIST, alertGroups);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
Set<Integer> ids = resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.ALERT_GROUP,
|
||||
loginUser.getId(), log);
|
||||
if (ids.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return alertGroupMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryNormalAlertgroup(User loginUser) {
|
||||
HashMap<String, Object> result = new HashMap<>();
|
||||
List<AlertGroup> alertGroups;
|
||||
if (loginUser.getUserType().equals(UserType.ADMIN_USER)) {
|
||||
alertGroups = alertGroupMapper.queryAllGroupList();
|
||||
} else {
|
||||
Set<Integer> ids = resourcePermissionCheckService
|
||||
.userOwnedResourceIdsAcquisition(AuthorizationType.ALERT_GROUP, loginUser.getId(), log);
|
||||
if (ids.isEmpty()) {
|
||||
result.put(Constants.DATA_LIST, Collections.emptyList());
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
alertGroups = alertGroupMapper.selectBatchIds(ids);
|
||||
}
|
||||
alertGroups = alertGroups.stream().filter(alertGroup -> alertGroup.getId() != 2).collect(Collectors.toList());
|
||||
result.put(Constants.DATA_LIST, alertGroups);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
public List<AlertGroup> queryNormalAlertGroups(User loginUser) {
|
||||
return queryAllAlertGroup(loginUser)
|
||||
.stream()
|
||||
// todo: remove the hardcode
|
||||
.filter(alertGroup -> alertGroup.getId() != 2)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* query alert group by id
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param id alert group id
|
||||
* @param id alert group id
|
||||
* @return one alert group
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> queryAlertGroupById(User loginUser, Integer id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put(Constants.STATUS, false);
|
||||
public AlertGroup queryAlertGroupById(User loginUser, Integer id) {
|
||||
|
||||
// only admin can operate
|
||||
if (!canOperatorPermissions(loginUser, new Object[]{id}, AuthorizationType.ALERT_GROUP, ALERT_GROUP_VIEW)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
// check if exist
|
||||
AlertGroup alertGroup = alertGroupMapper.selectById(id);
|
||||
if (alertGroup == null) {
|
||||
putMsg(result, Status.ALERT_GROUP_NOT_EXIST);
|
||||
return result;
|
||||
throw new ServiceException(Status.ALERT_GROUP_NOT_EXIST, id);
|
||||
}
|
||||
result.put("data", alertGroup);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return alertGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -146,35 +118,27 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup
|
|||
*
|
||||
* @param loginUser login user
|
||||
* @param searchVal search value
|
||||
* @param pageNo page number
|
||||
* @param pageSize page size
|
||||
* @param pageNo page number
|
||||
* @param pageSize page size
|
||||
* @return alert group list page
|
||||
*/
|
||||
@Override
|
||||
public Result listPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize) {
|
||||
|
||||
Result result = new Result();
|
||||
IPage<AlertGroup> alertGroupPage;
|
||||
PageInfo<AlertGroup> pageInfo = new PageInfo<>(pageNo, pageSize);
|
||||
public PageInfo<AlertGroup> listPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize) {
|
||||
Page<AlertGroup> page = new Page<>(pageNo, pageSize);
|
||||
if (loginUser.getUserType().equals(UserType.ADMIN_USER)) {
|
||||
alertGroupPage = alertGroupMapper.queryAlertGroupPage(page, searchVal);
|
||||
} else {
|
||||
Set<Integer> ids = resourcePermissionCheckService
|
||||
.userOwnedResourceIdsAcquisition(AuthorizationType.ALERT_GROUP, loginUser.getId(), log);
|
||||
if (ids.isEmpty()) {
|
||||
result.setData(pageInfo);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
alertGroupPage = alertGroupMapper.queryAlertGroupPageByIds(page, new ArrayList<>(ids), searchVal);
|
||||
IPage<AlertGroup> alertGroupIPage = alertGroupMapper.queryAlertGroupPage(page, searchVal);
|
||||
return PageInfo.of(alertGroupIPage);
|
||||
}
|
||||
pageInfo.setTotal((int) alertGroupPage.getTotal());
|
||||
pageInfo.setTotalList(alertGroupPage.getRecords());
|
||||
result.setData(pageInfo);
|
||||
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
Set<Integer> ids = resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.ALERT_GROUP,
|
||||
loginUser.getId(), log);
|
||||
if (ids.isEmpty()) {
|
||||
return PageInfo.of(pageNo, pageSize);
|
||||
}
|
||||
|
||||
IPage<AlertGroup> alertGroupIPage =
|
||||
alertGroupMapper.queryAlertGroupPageByIds(page, new ArrayList<>(ids), searchVal);
|
||||
return PageInfo.of(alertGroupIPage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -188,18 +152,15 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup
|
|||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public Map<String, Object> createAlertgroup(User loginUser, String groupName, String desc,
|
||||
String alertInstanceIds) {
|
||||
public AlertGroup createAlertGroup(User loginUser, String groupName, String desc, String alertInstanceIds) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
// only admin can operate
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.ALERT_GROUP, ALERT_GROUP_CREATE)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
if (checkDescriptionLength(desc)) {
|
||||
log.warn("Parameter description is too long.");
|
||||
putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
return result;
|
||||
throw new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
}
|
||||
AlertGroup alertGroup = new AlertGroup();
|
||||
Date now = new Date();
|
||||
|
|
@ -215,21 +176,15 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup
|
|||
try {
|
||||
int insert = alertGroupMapper.insert(alertGroup);
|
||||
if (insert > 0) {
|
||||
result.put(Constants.DATA_LIST, alertGroup);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
permissionPostHandle(AuthorizationType.ALERT_GROUP, loginUser.getId(),
|
||||
Collections.singletonList(alertGroup.getId()), log);
|
||||
log.info("Create alert group complete, groupName:{}", alertGroup.getGroupName());
|
||||
} else {
|
||||
log.error("Create alert group error, groupName:{}", alertGroup.getGroupName());
|
||||
putMsg(result, Status.CREATE_ALERT_GROUP_ERROR);
|
||||
return alertGroup;
|
||||
}
|
||||
log.error("Create alert group error, groupName:{}", alertGroup.getGroupName());
|
||||
throw new ServiceException(Status.CREATE_ALERT_GROUP_ERROR);
|
||||
} catch (DuplicateKeyException ex) {
|
||||
log.error("Create alert group error, groupName:{}", alertGroup.getGroupName(), ex);
|
||||
putMsg(result, Status.ALERT_GROUP_EXIST);
|
||||
throw new ServiceException(Status.ALERT_GROUP_EXIST);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -243,31 +198,24 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup
|
|||
* @return update result code
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> updateAlertgroup(User loginUser, int id, String groupName, String desc,
|
||||
String alertInstanceIds) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public AlertGroup updateAlertGroupById(User loginUser, int id, String groupName, String desc,
|
||||
String alertInstanceIds) {
|
||||
// don't allow to update global alert group
|
||||
// todo: remove hardcode
|
||||
if (id == 2) {
|
||||
putMsg(result, Status.NOT_ALLOW_TO_UPDATE_GLOBAL_ALARM_GROUP);
|
||||
return result;
|
||||
throw new ServiceException(Status.NOT_ALLOW_TO_UPDATE_GLOBAL_ALARM_GROUP);
|
||||
}
|
||||
|
||||
if (!canOperatorPermissions(loginUser, new Object[]{id}, AuthorizationType.ALERT_GROUP, ALERT_GROUP_UPDATE)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
if (checkDescriptionLength(desc)) {
|
||||
log.warn("Parameter description is too long.");
|
||||
putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
return result;
|
||||
throw new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
}
|
||||
AlertGroup alertGroup = alertGroupMapper.selectById(id);
|
||||
|
||||
if (alertGroup == null) {
|
||||
log.error("Alert group does not exist, id:{}.", id);
|
||||
putMsg(result, Status.ALERT_GROUP_NOT_EXIST);
|
||||
return result;
|
||||
|
||||
throw new ServiceException(Status.ALERT_GROUP_NOT_EXIST);
|
||||
}
|
||||
|
||||
Date now = new Date();
|
||||
|
|
@ -282,52 +230,42 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup
|
|||
try {
|
||||
alertGroupMapper.updateById(alertGroup);
|
||||
log.info("Update alert group complete, groupName:{}", alertGroup.getGroupName());
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return alertGroup;
|
||||
} catch (DuplicateKeyException ex) {
|
||||
log.error("Update alert group error, groupName:{}", alertGroup.getGroupName(), ex);
|
||||
putMsg(result, Status.ALERT_GROUP_EXIST);
|
||||
throw new ServiceException(Status.ALERT_GROUP_EXIST);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete alert group by id
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param id alert group id
|
||||
* @param id alert group id
|
||||
* @return delete result code
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public Map<String, Object> delAlertgroupById(User loginUser, int id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put(Constants.STATUS, false);
|
||||
public void deleteAlertGroupById(User loginUser, int id) {
|
||||
|
||||
// only admin can operate
|
||||
if (!canOperatorPermissions(loginUser, new Object[]{id}, AuthorizationType.ALERT_GROUP, ALERT_GROUP_DELETE)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
// Not allow to delete the default alarm group ,because the module of service need to use it.
|
||||
if (id == 1 || id == 2) {
|
||||
log.warn("Not allow to delete the default alarm group.");
|
||||
putMsg(result, Status.NOT_ALLOW_TO_DELETE_DEFAULT_ALARM_GROUP);
|
||||
return result;
|
||||
throw new ServiceException(Status.NOT_ALLOW_TO_DELETE_DEFAULT_ALARM_GROUP);
|
||||
}
|
||||
|
||||
// check exist
|
||||
AlertGroup alertGroup = alertGroupMapper.selectById(id);
|
||||
if (alertGroup == null) {
|
||||
log.error("Alert group does not exist, id:{}.", id);
|
||||
putMsg(result, Status.ALERT_GROUP_NOT_EXIST);
|
||||
return result;
|
||||
throw new ServiceException(Status.ALERT_GROUP_NOT_EXIST);
|
||||
}
|
||||
|
||||
alertGroupMapper.deleteById(id);
|
||||
log.info("Delete alert group complete, groupId:{}", id);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -23,11 +23,10 @@ import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationCon
|
|||
|
||||
import org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant;
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
|
||||
import org.apache.dolphinscheduler.api.service.AlertPluginInstanceService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.api.vo.AlertPluginInstanceVO;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.AlertPluginInstanceType;
|
||||
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
|
||||
import org.apache.dolphinscheduler.common.enums.WarningType;
|
||||
|
|
@ -55,7 +54,6 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
|
@ -67,6 +65,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
|
@ -96,15 +95,23 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A
|
|||
/**
|
||||
* creat alert plugin instance
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param pluginDefineId plugin define id
|
||||
* @param instanceName instance name
|
||||
* @param loginUser login user
|
||||
* @param pluginDefineId plugin define id
|
||||
* @param instanceName instance name
|
||||
* @param pluginInstanceParams plugin instance params
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> create(User loginUser, int pluginDefineId, String instanceName,
|
||||
AlertPluginInstanceType instanceType, WarningType warningType,
|
||||
public AlertPluginInstance create(User loginUser,
|
||||
int pluginDefineId,
|
||||
String instanceName,
|
||||
AlertPluginInstanceType instanceType,
|
||||
WarningType warningType,
|
||||
String pluginInstanceParams) {
|
||||
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.ALERT_PLUGIN_INSTANCE, ALART_INSTANCE_CREATE)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
AlertPluginInstance alertPluginInstance = new AlertPluginInstance();
|
||||
String paramsMapJson = parsePluginParamsMap(pluginInstanceParams);
|
||||
alertPluginInstance.setPluginInstanceParams(paramsMapJson);
|
||||
|
|
@ -113,16 +120,8 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A
|
|||
alertPluginInstance.setInstanceType(instanceType);
|
||||
alertPluginInstance.setWarningType(warningType);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.ALERT_PLUGIN_INSTANCE, ALART_INSTANCE_CREATE)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
}
|
||||
if (alertPluginInstanceMapper.existInstanceName(alertPluginInstance.getInstanceName()) == Boolean.TRUE) {
|
||||
log.error("Plugin instance with the same name already exists, name:{}.",
|
||||
alertPluginInstance.getInstanceName());
|
||||
putMsg(result, Status.PLUGIN_INSTANCE_ALREADY_EXISTS);
|
||||
return result;
|
||||
throw new ServiceException(Status.PLUGIN_INSTANCE_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
int i = alertPluginInstanceMapper.insert(alertPluginInstance);
|
||||
|
|
@ -142,94 +141,77 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A
|
|||
}
|
||||
alertGroupMapper.updateById(globalAlertGroup);
|
||||
}
|
||||
result.put(Constants.DATA_LIST, alertPluginInstance);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return alertPluginInstance;
|
||||
}
|
||||
log.error("Create alert plugin instance error, name:{}", alertPluginInstance.getInstanceName());
|
||||
putMsg(result, Status.SAVE_ERROR);
|
||||
return result;
|
||||
throw new ServiceException(Status.SAVE_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* update alert plugin instance
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param pluginInstanceId plugin instance id
|
||||
* @param instanceName instance name
|
||||
* @param loginUser login user
|
||||
* @param pluginInstanceId plugin instance id
|
||||
* @param instanceName instance name
|
||||
* @param pluginInstanceParams plugin instance params
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> update(User loginUser, int pluginInstanceId, String instanceName,
|
||||
WarningType warningType, String pluginInstanceParams) {
|
||||
public AlertPluginInstance updateById(User loginUser, int pluginInstanceId, String instanceName,
|
||||
WarningType warningType, String pluginInstanceParams) {
|
||||
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.ALERT_PLUGIN_INSTANCE, ALERT_PLUGIN_UPDATE)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
String paramsMapJson = parsePluginParamsMap(pluginInstanceParams);
|
||||
AlertPluginInstance alertPluginInstance =
|
||||
new AlertPluginInstance(pluginInstanceId, paramsMapJson, instanceName, warningType, new Date());
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.ALERT_PLUGIN_INSTANCE, ALERT_PLUGIN_UPDATE)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
}
|
||||
int i = alertPluginInstanceMapper.updateById(alertPluginInstance);
|
||||
|
||||
if (i > 0) {
|
||||
log.info("Update alert plugin instance complete, instanceId:{}, name:{}", alertPluginInstance.getId(),
|
||||
alertPluginInstance.getInstanceName());
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return alertPluginInstance;
|
||||
}
|
||||
log.error("Update alert plugin instance error, instanceId:{}, name:{}", alertPluginInstance.getId(),
|
||||
alertPluginInstance.getInstanceName());
|
||||
putMsg(result, Status.SAVE_ERROR);
|
||||
return result;
|
||||
throw new ServiceException(Status.SAVE_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete alert plugin instance
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param id id
|
||||
* @param loginUser login user
|
||||
* @param alertPluginInstanceId id
|
||||
* @return result
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> delete(User loginUser, int id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
AlertPluginInstance alertPluginInstance = alertPluginInstanceMapper.selectById(id);
|
||||
@Transactional
|
||||
public void deleteById(User loginUser, int alertPluginInstanceId) {
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.ALERT_PLUGIN_INSTANCE, ALERT_PLUGIN_DELETE)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
AlertPluginInstance alertPluginInstance = alertPluginInstanceMapper.selectById(alertPluginInstanceId);
|
||||
|
||||
if (alertPluginInstance.getInstanceType() == AlertPluginInstanceType.GLOBAL) {
|
||||
// global instance will be removed from global alert group automatically
|
||||
AlertGroup globalAlertGroup = alertGroupMapper.selectById(GLOBAL_ALERT_GROUP_ID);
|
||||
List<Integer> ids = Arrays.stream(globalAlertGroup.getAlertInstanceIds().split(","))
|
||||
.map(s -> Integer.parseInt(s.trim()))
|
||||
.collect(Collectors.toList());
|
||||
ids = ids.stream().filter(x -> x != id).collect(Collectors.toList());
|
||||
ids = ids.stream().filter(x -> x != alertPluginInstanceId).collect(Collectors.toList());
|
||||
globalAlertGroup.setAlertInstanceIds(StringUtils.join(ids, ","));
|
||||
alertGroupMapper.updateById(globalAlertGroup);
|
||||
log.info("Remove global alert plugin instance from global alert group automatically, name:{}",
|
||||
alertPluginInstance.getInstanceName());
|
||||
} else {
|
||||
// check if there is an associated alert group
|
||||
boolean hasAssociatedAlertGroup = checkHasAssociatedAlertGroup(String.valueOf(id));
|
||||
boolean hasAssociatedAlertGroup = checkHasAssociatedAlertGroup(String.valueOf(alertPluginInstanceId));
|
||||
if (hasAssociatedAlertGroup) {
|
||||
log.warn("Delete alert plugin failed because alert group is using it, pluginId:{}.", id);
|
||||
putMsg(result, Status.DELETE_ALERT_PLUGIN_INSTANCE_ERROR_HAS_ALERT_GROUP_ASSOCIATED);
|
||||
return result;
|
||||
throw new ServiceException(Status.DELETE_ALERT_PLUGIN_INSTANCE_ERROR_HAS_ALERT_GROUP_ASSOCIATED);
|
||||
}
|
||||
}
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.ALERT_PLUGIN_INSTANCE, ALERT_PLUGIN_DELETE)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
}
|
||||
|
||||
int i = alertPluginInstanceMapper.deleteById(id);
|
||||
if (i > 0) {
|
||||
log.info("Delete alert plugin instance complete, instanceId:{}", id);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
}
|
||||
log.error("Delete alert plugin instance error, instanceId:{}", id);
|
||||
return result;
|
||||
alertPluginInstanceMapper.deleteById(alertPluginInstanceId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -240,33 +222,18 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A
|
|||
* @return alert plugin
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> get(User loginUser, int id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
AlertPluginInstance alertPluginInstance = alertPluginInstanceMapper.selectById(id);
|
||||
public AlertPluginInstance getById(User loginUser, int id) {
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.ALERT_PLUGIN_INSTANCE,
|
||||
ApiFuncIdentificationConstant.ALARM_INSTANCE_MANAGE)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
if (null != alertPluginInstance) {
|
||||
putMsg(result, Status.SUCCESS);
|
||||
result.put(Constants.DATA_LIST, alertPluginInstance);
|
||||
}
|
||||
|
||||
return result;
|
||||
return alertPluginInstanceMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAll() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public List<AlertPluginInstanceVO> queryAll() {
|
||||
List<AlertPluginInstance> alertPluginInstances = alertPluginInstanceMapper.queryAllAlertPluginInstanceList();
|
||||
List<AlertPluginInstanceVO> alertPluginInstanceVOS = buildPluginInstanceVOList(alertPluginInstances);
|
||||
if (null != alertPluginInstances) {
|
||||
putMsg(result, Status.SUCCESS);
|
||||
result.put(Constants.DATA_LIST, alertPluginInstanceVOS);
|
||||
}
|
||||
return result;
|
||||
return buildPluginInstanceVOList(alertPluginInstances);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -275,19 +242,15 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result listPaging(User loginUser, String searchVal, int pageNo, int pageSize) {
|
||||
public PageInfo<AlertPluginInstanceVO> listPaging(User loginUser, String searchVal, int pageNo, int pageSize) {
|
||||
|
||||
Result result = new Result();
|
||||
Page<AlertPluginInstance> page = new Page<>(pageNo, pageSize);
|
||||
IPage<AlertPluginInstance> alertPluginInstanceIPage =
|
||||
alertPluginInstanceMapper.queryByInstanceNamePage(page, searchVal);
|
||||
alertPluginInstanceMapper.queryByInstanceNamePage(new Page<>(pageNo, pageSize), searchVal);
|
||||
|
||||
PageInfo<AlertPluginInstanceVO> pageInfo = new PageInfo<>(pageNo, pageSize);
|
||||
pageInfo.setTotal((int) alertPluginInstanceIPage.getTotal());
|
||||
pageInfo.setTotalList(buildPluginInstanceVOList(alertPluginInstanceIPage.getRecords()));
|
||||
result.setData(pageInfo);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
private List<AlertPluginInstanceVO> buildPluginInstanceVOList(List<AlertPluginInstance> alertPluginInstances) {
|
||||
|
|
@ -373,13 +336,10 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result<Void> testSend(int pluginDefineId, String pluginInstanceParams) {
|
||||
Result<Void> result = new Result<>();
|
||||
public void testSend(int pluginDefineId, String pluginInstanceParams) {
|
||||
Optional<Host> alertServerAddressOptional = getAlertServerAddress();
|
||||
if (!alertServerAddressOptional.isPresent()) {
|
||||
log.error("Cannot get alert server address, please check the alert server is running");
|
||||
putMsg(result, Status.ALERT_SERVER_NOT_EXIST);
|
||||
return result;
|
||||
throw new ServiceException(Status.ALERT_SERVER_NOT_EXIST);
|
||||
}
|
||||
|
||||
Host alertServerAddress = alertServerAddressOptional.get();
|
||||
|
|
@ -396,16 +356,12 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A
|
|||
log.info("Send alert to: {} successfully, response: {}", alertServerAddress, alertSendResponse);
|
||||
} catch (Exception e) {
|
||||
log.error("Send alert: {} to: {} failed", alertTestSendRequest, alertServerAddress, e);
|
||||
putMsg(result, Status.ALERT_TEST_SENDING_FAILED, e.getMessage());
|
||||
return result;
|
||||
throw new ServiceException(Status.ALERT_TEST_SENDING_FAILED, e.getMessage());
|
||||
}
|
||||
|
||||
if (alertSendResponse.isSuccess()) {
|
||||
putMsg(result, Status.SUCCESS);
|
||||
} else {
|
||||
putMsg(result, Status.ALERT_TEST_SENDING_FAILED, alertSendResponse.getResResults().get(0).getMessage());
|
||||
throw new ServiceException(Status.ALERT_TEST_SENDING_FAILED,
|
||||
alertSendResponse.getResResults().get(0).getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,17 +20,14 @@ package org.apache.dolphinscheduler.api.service.impl;
|
|||
import org.apache.dolphinscheduler.api.audit.AuditMessage;
|
||||
import org.apache.dolphinscheduler.api.audit.AuditPublishService;
|
||||
import org.apache.dolphinscheduler.api.dto.AuditDto;
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.service.AuditService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
|
||||
import org.apache.dolphinscheduler.common.enums.AuditResourceType;
|
||||
import org.apache.dolphinscheduler.dao.entity.AuditLog;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.dao.mapper.AuditLogMapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
|
@ -74,14 +71,17 @@ public class AuditServiceImpl extends BaseServiceImpl implements AuditService {
|
|||
* @param userName query user name
|
||||
* @param pageNo page number
|
||||
* @param pageSize page size
|
||||
* @return audit log string data
|
||||
* @return audit log string data
|
||||
*/
|
||||
@Override
|
||||
public Result queryLogListPaging(User loginUser, AuditResourceType resourceType,
|
||||
AuditOperationType operationType, String startDate,
|
||||
String endDate, String userName,
|
||||
Integer pageNo, Integer pageSize) {
|
||||
Result result = new Result();
|
||||
public PageInfo<AuditDto> queryLogListPaging(User loginUser,
|
||||
AuditResourceType resourceType,
|
||||
AuditOperationType operationType,
|
||||
String startDate,
|
||||
String endDate,
|
||||
String userName,
|
||||
Integer pageNo,
|
||||
Integer pageSize) {
|
||||
|
||||
int[] resourceArray = null;
|
||||
if (resourceType != null) {
|
||||
|
|
@ -93,20 +93,18 @@ public class AuditServiceImpl extends BaseServiceImpl implements AuditService {
|
|||
opsArray = new int[]{operationType.getCode()};
|
||||
}
|
||||
|
||||
Date start = (Date) checkAndParseDateParameters(startDate);
|
||||
Date end = (Date) checkAndParseDateParameters(endDate);
|
||||
Date start = checkAndParseDateParameters(startDate);
|
||||
Date end = checkAndParseDateParameters(endDate);
|
||||
|
||||
IPage<AuditLog> logIPage = auditLogMapper.queryAuditLog(new Page<>(pageNo, pageSize), resourceArray, opsArray,
|
||||
userName, start, end);
|
||||
List<AuditDto> auditDtos =
|
||||
logIPage.getRecords().stream().map(this::transformAuditLog).collect(Collectors.toList());
|
||||
|
||||
Page<AuditLog> page = new Page<>(pageNo, pageSize);
|
||||
IPage<AuditLog> logIPage = auditLogMapper.queryAuditLog(page, resourceArray, opsArray, userName, start, end);
|
||||
List<AuditLog> logList = logIPage != null ? logIPage.getRecords() : new ArrayList<>();
|
||||
PageInfo<AuditDto> pageInfo = new PageInfo<>(pageNo, pageSize);
|
||||
|
||||
List<AuditDto> auditDtos = logList.stream().map(this::transformAuditLog).collect(Collectors.toList());
|
||||
pageInfo.setTotal((int) (auditDtos != null ? auditDtos.size() : 0L));
|
||||
pageInfo.setTotal((int) auditDtos.size());
|
||||
pageInfo.setTotalList(auditDtos);
|
||||
result.setData(pageInfo);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -32,13 +32,11 @@ import org.apache.commons.lang3.StringUtils;
|
|||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
|
|
@ -50,17 +48,6 @@ public class BaseServiceImpl implements BaseService {
|
|||
@Autowired
|
||||
protected ResourcePermissionCheckService resourcePermissionCheckService;
|
||||
|
||||
@Override
|
||||
public void permissionPostHandle(AuthorizationType authorizationType, Integer userId, List<Integer> ids,
|
||||
Logger logger) {
|
||||
try {
|
||||
resourcePermissionCheckService.postHandle(authorizationType, userId, ids, logger);
|
||||
} catch (Exception e) {
|
||||
log.error("Post handle error, userId:{}.", userId, e);
|
||||
throw new RuntimeException("Resource association user error", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check admin
|
||||
*
|
||||
|
|
@ -76,17 +63,12 @@ public class BaseServiceImpl implements BaseService {
|
|||
* isNotAdmin
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param result result code
|
||||
* @return true if not administrator, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public boolean isNotAdmin(User loginUser, Map<String, Object> result) {
|
||||
public boolean isNotAdmin(User loginUser) {
|
||||
// only admin can operate
|
||||
if (!isAdmin(loginUser)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return !isAdmin(loginUser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -19,13 +19,12 @@ package org.apache.dolphinscheduler.api.service.impl;
|
|||
|
||||
import org.apache.dolphinscheduler.api.dto.ClusterDto;
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
|
||||
import org.apache.dolphinscheduler.api.k8s.K8sManager;
|
||||
import org.apache.dolphinscheduler.api.service.ClusterService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils;
|
||||
import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils.CodeGenerateException;
|
||||
import org.apache.dolphinscheduler.dao.entity.Cluster;
|
||||
import org.apache.dolphinscheduler.dao.entity.K8sNamespace;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
|
@ -36,11 +35,9 @@ import org.apache.dolphinscheduler.service.utils.ClusterConfUtils;
|
|||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -69,6 +66,7 @@ public class ClusterServiceImpl extends BaseServiceImpl implements ClusterServic
|
|||
|
||||
@Autowired
|
||||
private K8sNamespaceMapper k8sNamespaceMapper;
|
||||
|
||||
/**
|
||||
* create cluster
|
||||
*
|
||||
|
|
@ -79,23 +77,16 @@ public class ClusterServiceImpl extends BaseServiceImpl implements ClusterServic
|
|||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public Map<String, Object> createCluster(User loginUser, String name, String config, String desc) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (isNotAdmin(loginUser, result)) {
|
||||
log.warn("Only admin can create cluster, current login user name:{}.", loginUser.getUserName());
|
||||
return result;
|
||||
public Long createCluster(User loginUser, String name, String config, String desc) {
|
||||
if (isNotAdmin(loginUser)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
Map<String, Object> checkResult = checkParams(name, config);
|
||||
if (checkResult.get(Constants.STATUS) != Status.SUCCESS) {
|
||||
return checkResult;
|
||||
}
|
||||
checkParams(name, config);
|
||||
|
||||
Cluster clusterExistByName = clusterMapper.queryByClusterName(name);
|
||||
if (clusterExistByName != null) {
|
||||
log.warn("Cluster with the same name already exists, clusterName:{}.", clusterExistByName.getName());
|
||||
putMsg(result, Status.CLUSTER_NAME_EXISTS, name);
|
||||
return result;
|
||||
throw new ServiceException(Status.CLUSTER_NAME_EXISTS, name);
|
||||
}
|
||||
|
||||
Cluster cluster = new Cluster();
|
||||
|
|
@ -105,27 +96,12 @@ public class ClusterServiceImpl extends BaseServiceImpl implements ClusterServic
|
|||
cluster.setOperator(loginUser.getId());
|
||||
cluster.setCreateTime(new Date());
|
||||
cluster.setUpdateTime(new Date());
|
||||
long code = 0L;
|
||||
try {
|
||||
code = CodeGenerateUtils.getInstance().genCode();
|
||||
cluster.setCode(code);
|
||||
} catch (CodeGenerateException e) {
|
||||
log.error("Generate cluster code error.", e);
|
||||
}
|
||||
if (code == 0L) {
|
||||
putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS, "Error generating cluster code");
|
||||
return result;
|
||||
}
|
||||
cluster.setCode(CodeGenerateUtils.getInstance().genCode());
|
||||
|
||||
if (clusterMapper.insert(cluster) > 0) {
|
||||
log.info("Cluster create complete, clusterName:{}.", cluster.getName());
|
||||
result.put(Constants.DATA_LIST, cluster.getCode());
|
||||
putMsg(result, Status.SUCCESS);
|
||||
} else {
|
||||
log.error("Cluster create error, clusterName:{}.", cluster.getName());
|
||||
putMsg(result, Status.CREATE_CLUSTER_ERROR);
|
||||
return cluster.getCode();
|
||||
}
|
||||
return result;
|
||||
throw new ServiceException(Status.CREATE_CLUSTER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -137,8 +113,7 @@ public class ClusterServiceImpl extends BaseServiceImpl implements ClusterServic
|
|||
* @return cluster list page
|
||||
*/
|
||||
@Override
|
||||
public Result queryClusterListPaging(Integer pageNo, Integer pageSize, String searchVal) {
|
||||
Result result = new Result();
|
||||
public PageInfo<ClusterDto> queryClusterListPaging(Integer pageNo, Integer pageSize, String searchVal) {
|
||||
|
||||
Page<Cluster> page = new Page<>(pageNo, pageSize);
|
||||
|
||||
|
|
@ -147,22 +122,16 @@ public class ClusterServiceImpl extends BaseServiceImpl implements ClusterServic
|
|||
PageInfo<ClusterDto> pageInfo = new PageInfo<>(pageNo, pageSize);
|
||||
pageInfo.setTotal((int) clusterIPage.getTotal());
|
||||
|
||||
if (CollectionUtils.isNotEmpty(clusterIPage.getRecords())) {
|
||||
|
||||
List<ClusterDto> dtoList = clusterIPage.getRecords().stream().map(cluster -> {
|
||||
ClusterDto dto = new ClusterDto();
|
||||
BeanUtils.copyProperties(cluster, dto);
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
pageInfo.setTotalList(dtoList);
|
||||
} else {
|
||||
pageInfo.setTotalList(new ArrayList<>());
|
||||
if (CollectionUtils.isEmpty(clusterIPage.getRecords())) {
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
result.setData(pageInfo);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
List<ClusterDto> dtoList = clusterIPage.getRecords().stream().map(cluster -> {
|
||||
ClusterDto dto = new ClusterDto();
|
||||
BeanUtils.copyProperties(cluster, dto);
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
pageInfo.setTotalList(dtoList);
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -171,24 +140,19 @@ public class ClusterServiceImpl extends BaseServiceImpl implements ClusterServic
|
|||
* @return all cluster list
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> queryAllClusterList() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public List<ClusterDto> queryAllClusterList() {
|
||||
List<Cluster> clusterList = clusterMapper.queryAllClusterList();
|
||||
|
||||
if (CollectionUtils.isNotEmpty(clusterList)) {
|
||||
|
||||
List<ClusterDto> dtoList = clusterList.stream().map(cluster -> {
|
||||
ClusterDto dto = new ClusterDto();
|
||||
BeanUtils.copyProperties(cluster, dto);
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
result.put(Constants.DATA_LIST, dtoList);
|
||||
} else {
|
||||
result.put(Constants.DATA_LIST, new ArrayList<>());
|
||||
if (CollectionUtils.isEmpty(clusterList)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return clusterList.stream()
|
||||
.map(cluster -> {
|
||||
ClusterDto dto = new ClusterDto();
|
||||
// todo: Don't use copy
|
||||
BeanUtils.copyProperties(cluster, dto);
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -197,21 +161,16 @@ public class ClusterServiceImpl extends BaseServiceImpl implements ClusterServic
|
|||
* @param code cluster code
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> queryClusterByCode(Long code) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public ClusterDto queryClusterByCode(Long code) {
|
||||
|
||||
Cluster cluster = clusterMapper.queryByClusterCode(code);
|
||||
|
||||
if (cluster == null) {
|
||||
putMsg(result, Status.QUERY_CLUSTER_BY_CODE_ERROR, code);
|
||||
} else {
|
||||
|
||||
ClusterDto dto = new ClusterDto();
|
||||
BeanUtils.copyProperties(cluster, dto);
|
||||
result.put(Constants.DATA_LIST, dto);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
throw new ServiceException(Status.QUERY_CLUSTER_BY_CODE_ERROR, code);
|
||||
}
|
||||
return result;
|
||||
ClusterDto dto = new ClusterDto();
|
||||
BeanUtils.copyProperties(cluster, dto);
|
||||
return dto;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -220,21 +179,15 @@ public class ClusterServiceImpl extends BaseServiceImpl implements ClusterServic
|
|||
* @param name cluster name
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> queryClusterByName(String name) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public ClusterDto queryClusterByName(String name) {
|
||||
|
||||
Cluster cluster = clusterMapper.queryByClusterName(name);
|
||||
if (cluster == null) {
|
||||
log.warn("Cluster does not exist, name:{}.", name);
|
||||
putMsg(result, Status.QUERY_CLUSTER_BY_NAME_ERROR, name);
|
||||
} else {
|
||||
|
||||
ClusterDto dto = new ClusterDto();
|
||||
BeanUtils.copyProperties(cluster, dto);
|
||||
result.put(Constants.DATA_LIST, dto);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
throw new ServiceException(Status.QUERY_CLUSTER_BY_NAME_ERROR, name);
|
||||
}
|
||||
return result;
|
||||
ClusterDto dto = new ClusterDto();
|
||||
BeanUtils.copyProperties(cluster, dto);
|
||||
return dto;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -243,34 +196,24 @@ public class ClusterServiceImpl extends BaseServiceImpl implements ClusterServic
|
|||
* @param loginUser login user
|
||||
* @param code cluster code
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public Map<String, Object> deleteClusterByCode(User loginUser, Long code) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (isNotAdmin(loginUser, result)) {
|
||||
log.warn("Only admin can delete cluster, current login user name:{}.", loginUser.getUserName());
|
||||
return result;
|
||||
public void deleteClusterByCode(User loginUser, Long code) {
|
||||
if (isNotAdmin(loginUser)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
Long relatedNamespaceNumber = k8sNamespaceMapper
|
||||
.selectCount(new QueryWrapper<K8sNamespace>().lambda().eq(K8sNamespace::getClusterCode, code));
|
||||
|
||||
if (relatedNamespaceNumber > 0) {
|
||||
log.warn("Delete cluster failed because {} namespace(s) is(are) using it, clusterCode:{}.",
|
||||
relatedNamespaceNumber, code);
|
||||
putMsg(result, Status.DELETE_CLUSTER_RELATED_NAMESPACE_EXISTS);
|
||||
return result;
|
||||
throw new ServiceException(Status.DELETE_CLUSTER_RELATED_NAMESPACE_EXISTS);
|
||||
}
|
||||
|
||||
int delete = clusterMapper.deleteByCode(code);
|
||||
if (delete > 0) {
|
||||
log.info("Delete cluster complete, clusterCode:{}.", code);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
} else {
|
||||
log.error("Delete cluster error, clusterCode:{}.", code);
|
||||
putMsg(result, Status.DELETE_CLUSTER_ERROR);
|
||||
return;
|
||||
}
|
||||
return result;
|
||||
throw new ServiceException(Status.DELETE_CLUSTER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -282,38 +225,30 @@ public class ClusterServiceImpl extends BaseServiceImpl implements ClusterServic
|
|||
* @param config cluster config
|
||||
* @param desc cluster desc
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public Map<String, Object> updateClusterByCode(User loginUser, Long code, String name, String config, String desc) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (isNotAdmin(loginUser, result)) {
|
||||
log.warn("Only admin can update cluster, current login user name:{}.", loginUser.getUserName());
|
||||
return result;
|
||||
public Cluster updateClusterByCode(User loginUser,
|
||||
Long code,
|
||||
String name,
|
||||
String config,
|
||||
String desc) {
|
||||
if (isNotAdmin(loginUser)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
if (checkDescriptionLength(desc)) {
|
||||
log.warn("Parameter description is too long.");
|
||||
putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
return result;
|
||||
throw new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
}
|
||||
|
||||
Map<String, Object> checkResult = checkParams(name, config);
|
||||
if (checkResult.get(Constants.STATUS) != Status.SUCCESS) {
|
||||
return checkResult;
|
||||
}
|
||||
checkParams(name, config);
|
||||
|
||||
Cluster clusterExistByName = clusterMapper.queryByClusterName(name);
|
||||
if (clusterExistByName != null && !clusterExistByName.getCode().equals(code)) {
|
||||
log.warn("Cluster with the same name already exists, name:{}.", clusterExistByName.getName());
|
||||
putMsg(result, Status.CLUSTER_NAME_EXISTS, name);
|
||||
return result;
|
||||
throw new ServiceException(Status.CLUSTER_NAME_EXISTS, name);
|
||||
}
|
||||
|
||||
Cluster clusterExist = clusterMapper.queryByClusterCode(code);
|
||||
if (clusterExist == null) {
|
||||
log.error("Cluster does not exist, code:{}.", code);
|
||||
putMsg(result, Status.CLUSTER_NOT_EXISTS, name);
|
||||
return result;
|
||||
throw new ServiceException(Status.CLUSTER_NOT_EXISTS, name);
|
||||
}
|
||||
|
||||
if (!Constants.K8S_LOCAL_TEST_CLUSTER_CODE.equals(clusterExist.getCode())
|
||||
|
|
@ -321,21 +256,17 @@ public class ClusterServiceImpl extends BaseServiceImpl implements ClusterServic
|
|||
try {
|
||||
k8sManager.getAndUpdateK8sClient(code, true);
|
||||
} catch (Exception e) {
|
||||
log.error("Update K8s error.", e);
|
||||
putMsg(result, Status.K8S_CLIENT_OPS_ERROR, name);
|
||||
return result;
|
||||
throw new ServiceException(Status.K8S_CLIENT_OPS_ERROR, name);
|
||||
}
|
||||
}
|
||||
|
||||
// update cluster
|
||||
// need not update relation
|
||||
clusterExist.setConfig(config);
|
||||
clusterExist.setName(name);
|
||||
clusterExist.setDescription(desc);
|
||||
clusterMapper.updateById(clusterExist);
|
||||
// need not update relation
|
||||
log.info("Cluster update complete, clusterId:{}.", clusterExist.getId());
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return clusterExist;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -345,40 +276,25 @@ public class ClusterServiceImpl extends BaseServiceImpl implements ClusterServic
|
|||
* @return true if the cluster name not exists, otherwise return false
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> verifyCluster(String clusterName) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public void verifyCluster(String clusterName) {
|
||||
|
||||
if (StringUtils.isEmpty(clusterName)) {
|
||||
log.warn("Parameter cluster name is empty.");
|
||||
putMsg(result, Status.CLUSTER_NAME_IS_NULL);
|
||||
return result;
|
||||
throw new ServiceException(Status.CLUSTER_NAME_IS_NULL);
|
||||
}
|
||||
|
||||
Cluster cluster = clusterMapper.queryByClusterName(clusterName);
|
||||
if (cluster != null) {
|
||||
log.warn("Cluster with the same name already exists, name:{}.", cluster.getName());
|
||||
putMsg(result, Status.CLUSTER_NAME_EXISTS, clusterName);
|
||||
return result;
|
||||
throw new ServiceException(Status.CLUSTER_NAME_EXISTS);
|
||||
}
|
||||
|
||||
result.put(Constants.STATUS, Status.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Map<String, Object> checkParams(String name, String config) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
protected void checkParams(String name, String config) {
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
log.warn("Parameter cluster name is empty.");
|
||||
putMsg(result, Status.CLUSTER_NAME_IS_NULL);
|
||||
return result;
|
||||
throw new ServiceException(Status.CLUSTER_NAME_IS_NULL);
|
||||
}
|
||||
if (StringUtils.isEmpty(config)) {
|
||||
log.warn("Parameter cluster config is empty.");
|
||||
putMsg(result, Status.CLUSTER_CONFIG_IS_NULL);
|
||||
return result;
|
||||
throw new ServiceException(Status.CLUSTER_CONFIG_IS_NULL);
|
||||
}
|
||||
result.put(Constants.STATUS, Status.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import org.apache.dolphinscheduler.api.dto.DefineUserDto;
|
|||
import org.apache.dolphinscheduler.api.dto.TaskCountDto;
|
||||
import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
|
||||
import org.apache.dolphinscheduler.api.service.DataAnalysisService;
|
||||
import org.apache.dolphinscheduler.api.service.ProjectService;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
|
|
@ -35,6 +36,7 @@ import org.apache.dolphinscheduler.common.utils.TriFunction;
|
|||
import org.apache.dolphinscheduler.dao.entity.CommandCount;
|
||||
import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser;
|
||||
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
|
||||
import org.apache.dolphinscheduler.dao.entity.Project;
|
||||
import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
|
@ -101,6 +103,7 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
|
||||
@Autowired
|
||||
private ProcessTaskRelationMapper relationMapper;
|
||||
|
||||
/**
|
||||
* statistical task instance status data
|
||||
*
|
||||
|
|
@ -111,8 +114,8 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
* @return task state count data
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> countTaskStateByProject(User loginUser, long projectCode, String startDate,
|
||||
String endDate) {
|
||||
public TaskCountDto countTaskStateByProject(User loginUser, long projectCode, String startDate,
|
||||
String endDate) {
|
||||
|
||||
return countStateByProject(
|
||||
loginUser,
|
||||
|
|
@ -132,22 +135,21 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
* @return process instance state count data
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> countProcessInstanceStateByProject(User loginUser, long projectCode, String startDate,
|
||||
String endDate) {
|
||||
Map<String, Object> result = this.countStateByProject(
|
||||
public TaskCountDto countProcessInstanceStateByProject(User loginUser, long projectCode, String startDate,
|
||||
String endDate) {
|
||||
TaskCountDto taskCountDto = countStateByProject(
|
||||
loginUser,
|
||||
projectCode,
|
||||
startDate,
|
||||
endDate,
|
||||
(start, end, projectCodes) -> this.processInstanceMapper.countInstanceStateByProjectCodes(start, end,
|
||||
(start, end, projectCodes) -> processInstanceMapper.countInstanceStateByProjectCodes(start, end,
|
||||
projectCodes));
|
||||
|
||||
// process state count needs to remove state of forced success
|
||||
if (result.containsKey(Constants.STATUS) && result.get(Constants.STATUS).equals(Status.SUCCESS)) {
|
||||
((TaskCountDto) result.get(Constants.DATA_LIST))
|
||||
.removeStateFromCountList(TaskExecutionStatus.FORCED_SUCCESS);
|
||||
if (taskCountDto != null) {
|
||||
taskCountDto.removeStateFromCountList(TaskExecutionStatus.FORCED_SUCCESS);
|
||||
}
|
||||
return result;
|
||||
return taskCountDto;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -158,15 +160,13 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
* @param startDate start date
|
||||
* @param endDate end date
|
||||
*/
|
||||
private Map<String, Object> countStateByProject(User loginUser, long projectCode, String startDate, String endDate,
|
||||
TriFunction<Date, Date, Long[], List<ExecuteStatusCount>> instanceStateCounter) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
private TaskCountDto countStateByProject(User loginUser,
|
||||
long projectCode,
|
||||
String startDate,
|
||||
String endDate,
|
||||
TriFunction<Date, Date, Long[], List<ExecuteStatusCount>> instanceStateCounter) {
|
||||
if (projectCode != 0) {
|
||||
Project project = projectMapper.queryByCode(projectCode);
|
||||
result = projectService.checkProjectAndAuth(loginUser, project, projectCode, PROJECT_OVERVIEW);
|
||||
if (result.get(Constants.STATUS) != Status.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW);
|
||||
}
|
||||
|
||||
Date start = null;
|
||||
|
|
@ -175,12 +175,10 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
start = DateUtils.stringToDate(startDate);
|
||||
end = DateUtils.stringToDate(endDate);
|
||||
if (Objects.isNull(start) || Objects.isNull(end)) {
|
||||
log.warn("Parameter startDate or endDate is invalid.");
|
||||
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.START_END_DATE);
|
||||
return result;
|
||||
throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.START_END_DATE);
|
||||
}
|
||||
}
|
||||
Pair<Set<Integer>, Map<String, Object>> projectIds = getProjectIds(loginUser, result);
|
||||
Pair<Set<Integer>, TaskCountDto> projectIds = getProjectIds(loginUser);
|
||||
if (projectIds.getRight() != null) {
|
||||
return projectIds.getRight();
|
||||
}
|
||||
|
|
@ -193,11 +191,9 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
}
|
||||
|
||||
if (processInstanceStateCounts != null) {
|
||||
TaskCountDto taskCountResult = new TaskCountDto(processInstanceStateCounts);
|
||||
result.put(Constants.DATA_LIST, taskCountResult);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return new TaskCountDto(processInstanceStateCounts);
|
||||
}
|
||||
return result;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -210,35 +206,26 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
* @return definition count data
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> countDefinitionByUser(User loginUser, long projectCode) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public DefineUserDto countDefinitionByUser(User loginUser, long projectCode) {
|
||||
if (projectCode != 0) {
|
||||
Project project = projectMapper.queryByCode(projectCode);
|
||||
result = projectService.checkProjectAndAuth(loginUser, project, projectCode, PROJECT_OVERVIEW);
|
||||
if (result.get(Constants.STATUS) != Status.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW);
|
||||
}
|
||||
|
||||
// todo: refactor this method, don't use Pair
|
||||
Pair<Set<Integer>, TaskCountDto> projectIds = getProjectIds(loginUser);
|
||||
if (projectIds.getRight() != null) {
|
||||
List<DefinitionGroupByUser> emptyList = new ArrayList<>();
|
||||
return new DefineUserDto(emptyList);
|
||||
}
|
||||
|
||||
List<DefinitionGroupByUser> defineGroupByUsers = new ArrayList<>();
|
||||
Pair<Set<Integer>, Map<String, Object>> projectIds = getProjectIds(loginUser, result);
|
||||
if (projectIds.getRight() != null) {
|
||||
List<DefinitionGroupByUser> emptyList = new ArrayList<>();
|
||||
DefineUserDto dto = new DefineUserDto(emptyList);
|
||||
result.put(Constants.DATA_LIST, dto);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
Long[] projectCodeArray =
|
||||
projectCode == 0 ? getProjectCodesArrays(projectIds.getLeft()) : new Long[]{projectCode};
|
||||
if (projectCodeArray.length != 0 || loginUser.getUserType() == UserType.ADMIN_USER) {
|
||||
defineGroupByUsers = processDefinitionMapper.countDefinitionByProjectCodes(projectCodeArray);
|
||||
}
|
||||
|
||||
DefineUserDto dto = new DefineUserDto(defineGroupByUsers);
|
||||
result.put(Constants.DATA_LIST, dto);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return new DefineUserDto(defineGroupByUsers);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -248,8 +235,7 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
* @return command state count data
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> countCommandState(User loginUser) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public List<CommandStateCount> countCommandState(User loginUser) {
|
||||
|
||||
/**
|
||||
* find all the task lists in the project under the user
|
||||
|
|
@ -257,13 +243,12 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
*/
|
||||
Date start = null;
|
||||
Date end = null;
|
||||
Pair<Set<Integer>, Map<String, Object>> projectIds = getProjectIds(loginUser, result);
|
||||
Pair<Set<Integer>, TaskCountDto> projectIds = getProjectIds(loginUser);
|
||||
if (projectIds.getRight() != null) {
|
||||
List<CommandStateCount> noData = Arrays.stream(CommandType.values())
|
||||
.map(commandType -> new CommandStateCount(0, 0, commandType)).collect(Collectors.toList());
|
||||
result.put(Constants.DATA_LIST, noData);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
.map(commandType -> new CommandStateCount(0, 0, commandType))
|
||||
.collect(Collectors.toList());
|
||||
return noData;
|
||||
}
|
||||
Long[] projectCodeArray = getProjectCodesArrays(projectIds.getLeft());
|
||||
// count normal command state
|
||||
|
|
@ -284,20 +269,15 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
normalCountCommandCounts.getOrDefault(commandType, 0),
|
||||
commandType))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
result.put(Constants.DATA_LIST, list);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return list;
|
||||
}
|
||||
|
||||
private Pair<Set<Integer>, Map<String, Object>> getProjectIds(User loginUser, Map<String, Object> result) {
|
||||
private Pair<Set<Integer>, TaskCountDto> getProjectIds(User loginUser) {
|
||||
Set<Integer> projectIds = resourcePermissionCheckService
|
||||
.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), log);
|
||||
if (projectIds.isEmpty()) {
|
||||
List<ExecuteStatusCount> taskInstanceStateCounts = new ArrayList<>();
|
||||
result.put(Constants.DATA_LIST, new TaskCountDto(taskInstanceStateCounts));
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return Pair.of(null, result);
|
||||
return Pair.of(null, new TaskCountDto(taskInstanceStateCounts));
|
||||
}
|
||||
return Pair.of(projectIds, null);
|
||||
}
|
||||
|
|
@ -316,16 +296,14 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
* @return queue state count data
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> countQueueState(User loginUser) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public Map<String, Integer> countQueueState(User loginUser) {
|
||||
|
||||
// TODO need to add detail data info
|
||||
// todo: refactor this method, don't use Map
|
||||
Map<String, Integer> dataMap = new HashMap<>();
|
||||
dataMap.put("taskQueue", 0);
|
||||
dataMap.put("taskKill", 0);
|
||||
result.put(Constants.DATA_LIST, dataMap);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -375,6 +353,7 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
List<Long> projectCodes = projects.stream().map(project -> project.getCode()).collect(Collectors.toList());
|
||||
count = projectMapper.queryAllWorkflowCounts(projectCodes);
|
||||
}
|
||||
// todo: refactor this method, don't use Map
|
||||
result.put("data", "AllWorkflowCounts = " + count);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
|
|
@ -382,19 +361,18 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
|
||||
/**
|
||||
* query all workflow states count
|
||||
* @param loginUser login user
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param statisticsStateRequest statisticsStateRequest
|
||||
* @return workflow states count
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> countWorkflowStates(User loginUser,
|
||||
StatisticsStateRequest statisticsStateRequest) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public TaskCountDto countWorkflowStates(User loginUser,
|
||||
StatisticsStateRequest statisticsStateRequest) {
|
||||
Set<Integer> projectIds = resourcePermissionCheckService
|
||||
.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), log);
|
||||
if (projectIds.isEmpty()) {
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return new TaskCountDto(Collections.emptyList());
|
||||
}
|
||||
|
||||
String projectName = statisticsStateRequest.getProjectName();
|
||||
|
|
@ -425,50 +403,42 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
|
||||
List<ExecuteStatusCount> executeStatusCounts = processInstanceMapper.countInstanceStateV2(
|
||||
startTime, endTime, projectCode, workflowCode, model, projectIds);
|
||||
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
|
||||
result.put(Constants.DATA_LIST, taskCountResult);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return new TaskCountDto(executeStatusCounts);
|
||||
}
|
||||
|
||||
/**
|
||||
* query one workflow states count
|
||||
* @param loginUser login user
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param workflowCode workflowCode
|
||||
* @return workflow states count
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> countOneWorkflowStates(User loginUser, Long workflowCode) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Project project = projectMapper.queryByCode(workflowCode);
|
||||
boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result);
|
||||
if (!hasProjectAndWritePerm) {
|
||||
return result;
|
||||
public TaskCountDto countOneWorkflowStates(User loginUser, Long workflowCode) {
|
||||
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(workflowCode);
|
||||
if (processDefinition == null) {
|
||||
throw new ServiceException(Status.PROCESS_DEFINE_NOT_EXIST, workflowCode);
|
||||
}
|
||||
List<ExecuteStatusCount> executeStatusCounts = processInstanceMapper.countInstanceStateV2(
|
||||
null, null, null, workflowCode, Constants.QUERY_ALL_ON_WORKFLOW, null);
|
||||
if (executeStatusCounts != null) {
|
||||
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
|
||||
result.put(Constants.DATA_LIST, taskCountResult);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
}
|
||||
return result;
|
||||
projectService.checkHasProjectWritePermissionThrowException(loginUser, processDefinition.getProjectCode());
|
||||
|
||||
List<ExecuteStatusCount> executeStatusCounts = processInstanceMapper.countInstanceStateV2(null, null, null,
|
||||
workflowCode, Constants.QUERY_ALL_ON_WORKFLOW, null);
|
||||
return new TaskCountDto(executeStatusCounts);
|
||||
}
|
||||
|
||||
/**
|
||||
* query all task states count
|
||||
* @param loginUser login user
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param statisticsStateRequest statisticsStateRequest
|
||||
* @return tasks states count
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> countTaskStates(User loginUser, StatisticsStateRequest statisticsStateRequest) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public TaskCountDto countTaskStates(User loginUser, StatisticsStateRequest statisticsStateRequest) {
|
||||
Set<Integer> projectIds = resourcePermissionCheckService
|
||||
.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), log);
|
||||
if (projectIds.isEmpty()) {
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return new TaskCountDto(Collections.emptyList());
|
||||
}
|
||||
String projectName = statisticsStateRequest.getProjectName();
|
||||
String workflowName = statisticsStateRequest.getWorkflowName();
|
||||
|
|
@ -508,10 +478,7 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
taskInstanceMapper.countTaskInstanceStateByProjectIdsV2(startTime, endTime, projectIds));
|
||||
List<TaskExecutionStatus> needRecountState = setOptional(startTimeStates);
|
||||
if (needRecountState.size() == 0) {
|
||||
TaskCountDto taskCountResult = new TaskCountDto(startTimeStates.get());
|
||||
result.put(Constants.DATA_LIST, taskCountResult);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return new TaskCountDto(startTimeStates.get());
|
||||
}
|
||||
List<ExecuteStatusCount> recounts = this.taskInstanceMapper
|
||||
.countTaskInstanceStateByProjectCodesAndStatesBySubmitTimeV2(startTime, endTime, projectCode,
|
||||
|
|
@ -519,37 +486,29 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
needRecountState);
|
||||
startTimeStates.orElseGet(ArrayList::new).addAll(recounts);
|
||||
List<ExecuteStatusCount> executeStatusCounts = startTimeStates.orElse(null);
|
||||
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
|
||||
result.put(Constants.DATA_LIST, taskCountResult);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return new TaskCountDto(executeStatusCounts);
|
||||
}
|
||||
|
||||
/**
|
||||
* query one task states count
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param taskCode taskCode
|
||||
* @param taskCode taskCode
|
||||
* @return tasks states count
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> countOneTaskStates(User loginUser, Long taskCode) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public TaskCountDto countOneTaskStates(User loginUser, Long taskCode) {
|
||||
TaskDefinition taskDefinition = taskDefinitionMapper.queryByCode(taskCode);
|
||||
long projectCode = taskDefinition.getProjectCode();
|
||||
Project project = projectMapper.queryByCode(projectCode);
|
||||
boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result);
|
||||
if (!hasProjectAndWritePerm) {
|
||||
return result;
|
||||
}
|
||||
projectService.checkHasProjectWritePermissionThrowException(loginUser, project);
|
||||
|
||||
Set<Integer> projectId = Collections.singleton(project.getId());
|
||||
Optional<List<ExecuteStatusCount>> startTimeStates = Optional.ofNullable(
|
||||
taskInstanceMapper.countTaskInstanceStateByProjectIdsV2(null, null, projectId));
|
||||
List<TaskExecutionStatus> needRecountState = setOptional(startTimeStates);
|
||||
if (needRecountState.size() == 0) {
|
||||
TaskCountDto taskCountResult = new TaskCountDto(startTimeStates.get());
|
||||
result.put(Constants.DATA_LIST, taskCountResult);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return new TaskCountDto(startTimeStates.get());
|
||||
}
|
||||
List<ExecuteStatusCount> recounts = this.taskInstanceMapper
|
||||
.countTaskInstanceStateByProjectCodesAndStatesBySubmitTimeV2(null, null, projectCode, null, taskCode,
|
||||
|
|
@ -557,10 +516,7 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
needRecountState);
|
||||
startTimeStates.orElseGet(ArrayList::new).addAll(recounts);
|
||||
List<ExecuteStatusCount> executeStatusCounts = startTimeStates.orElse(null);
|
||||
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
|
||||
result.put(Constants.DATA_LIST, taskCountResult);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return new TaskCountDto(executeStatusCounts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -573,25 +529,18 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
* @return definition count data
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> countDefinitionByUserV2(User loginUser, Long projectCode, Integer userId,
|
||||
Integer releaseState) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public DefineUserDto countDefinitionByUserV2(User loginUser, Long projectCode, Integer userId,
|
||||
Integer releaseState) {
|
||||
if (null != projectCode) {
|
||||
Project project = projectMapper.queryByCode(projectCode);
|
||||
result = projectService.checkProjectAndAuth(loginUser, project, projectCode, PROJECT_OVERVIEW);
|
||||
if (result.get(Constants.STATUS) != Status.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
projectService.checkProjectAndAuth(loginUser, project, projectCode, PROJECT_OVERVIEW);
|
||||
}
|
||||
|
||||
List<DefinitionGroupByUser> defineGroupByUsers = new ArrayList<>();
|
||||
Pair<Set<Integer>, Map<String, Object>> projectIds = getProjectIds(loginUser, result);
|
||||
Pair<Set<Integer>, TaskCountDto> projectIds = getProjectIds(loginUser);
|
||||
if (projectIds.getRight() != null) {
|
||||
List<DefinitionGroupByUser> emptyList = new ArrayList<>();
|
||||
DefineUserDto dto = new DefineUserDto(emptyList);
|
||||
result.put(Constants.DATA_LIST, dto);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return new DefineUserDto(emptyList);
|
||||
}
|
||||
Long[] projectCodeArray =
|
||||
projectCode == null ? getProjectCodesArrays(projectIds.getLeft()) : new Long[]{projectCode};
|
||||
|
|
@ -600,10 +549,7 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
|
|||
processDefinitionMapper.countDefinitionByProjectCodesV2(projectCodeArray, userId, releaseState);
|
||||
}
|
||||
|
||||
DefineUserDto dto = new DefineUserDto(defineGroupByUsers);
|
||||
result.put(Constants.DATA_LIST, dto);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return new DefineUserDto(defineGroupByUsers);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import org.apache.dolphinscheduler.api.enums.Status;
|
|||
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
|
||||
import org.apache.dolphinscheduler.api.service.DataSourceService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
|
|
@ -90,30 +89,23 @@ public class DataSourceServiceImpl extends BaseServiceImpl implements DataSource
|
|||
/**
|
||||
* create data source
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param loginUser login user
|
||||
* @param datasourceParam datasource parameters
|
||||
* @return create result code
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public Result<Object> createDataSource(User loginUser, BaseDataSourceParamDTO datasourceParam) {
|
||||
public DataSource createDataSource(User loginUser, BaseDataSourceParamDTO datasourceParam) {
|
||||
DataSourceUtils.checkDatasourceParam(datasourceParam);
|
||||
Result<Object> result = new Result<>();
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.DATASOURCE,
|
||||
ApiFuncIdentificationConstant.DATASOURCE_CREATE_DATASOURCE)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
// check name can use or not
|
||||
if (checkName(datasourceParam.getName())) {
|
||||
log.warn("Datasource with the same name already exists, name:{}.", datasourceParam.getName());
|
||||
putMsg(result, Status.DATASOURCE_EXIST);
|
||||
return result;
|
||||
throw new ServiceException(Status.DATASOURCE_EXIST);
|
||||
}
|
||||
if (checkDescriptionLength(datasourceParam.getNote())) {
|
||||
log.warn("Parameter description is too long, description:{}.", datasourceParam.getNote());
|
||||
putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
return result;
|
||||
throw new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
}
|
||||
ConnectionParam connectionParam = DataSourceUtils.buildConnectionParams(datasourceParam);
|
||||
|
||||
|
|
@ -131,54 +123,38 @@ public class DataSourceServiceImpl extends BaseServiceImpl implements DataSource
|
|||
dataSource.setUpdateTime(now);
|
||||
try {
|
||||
dataSourceMapper.insert(dataSource);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
permissionPostHandle(AuthorizationType.DATASOURCE, loginUser.getId(),
|
||||
Collections.singletonList(dataSource.getId()), log);
|
||||
log.info("Datasource create complete, dbType:{}, datasourceName:{}.", dataSource.getType().getDescp(),
|
||||
dataSource.getName());
|
||||
return dataSource;
|
||||
} catch (DuplicateKeyException ex) {
|
||||
log.error("Datasource create error.", ex);
|
||||
putMsg(result, Status.DATASOURCE_EXIST);
|
||||
throw new ServiceException(Status.DATASOURCE_EXIST);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* updateProcessInstance datasource
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param id data source id
|
||||
* @return update result code
|
||||
*/
|
||||
@Override
|
||||
public Result<Object> updateDataSource(int id, User loginUser, BaseDataSourceParamDTO dataSourceParam) {
|
||||
public DataSource updateDataSource(User loginUser, BaseDataSourceParamDTO dataSourceParam) {
|
||||
DataSourceUtils.checkDatasourceParam(dataSourceParam);
|
||||
Result<Object> result = new Result<>();
|
||||
// determine whether the data source exists
|
||||
DataSource dataSource = dataSourceMapper.selectById(id);
|
||||
DataSource dataSource = dataSourceMapper.selectById(dataSourceParam.getId());
|
||||
if (dataSource == null) {
|
||||
log.error("Datasource does not exist, id:{}.", id);
|
||||
putMsg(result, Status.RESOURCE_NOT_EXIST);
|
||||
return result;
|
||||
throw new ServiceException(Status.RESOURCE_NOT_EXIST);
|
||||
}
|
||||
|
||||
if (!canOperatorPermissions(loginUser, new Object[]{dataSource.getId()}, AuthorizationType.DATASOURCE,
|
||||
DATASOURCE_UPDATE)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
// check name can use or not
|
||||
if (!dataSourceParam.getName().trim().equals(dataSource.getName()) && checkName(dataSourceParam.getName())) {
|
||||
log.warn("Datasource with the same name already exists, name:{}.", dataSource.getName());
|
||||
putMsg(result, Status.DATASOURCE_EXIST);
|
||||
return result;
|
||||
throw new ServiceException(Status.DATASOURCE_EXIST);
|
||||
}
|
||||
if (checkDescriptionLength(dataSourceParam.getNote())) {
|
||||
log.warn("Parameter description is too long, description:{}.", dataSourceParam.getNote());
|
||||
putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
return result;
|
||||
throw new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
}
|
||||
// check password,if the password is not updated, set to the old password.
|
||||
ConnectionParam connectionParam = DataSourceUtils.buildConnectionParams(dataSourceParam);
|
||||
|
|
@ -201,15 +177,10 @@ public class DataSourceServiceImpl extends BaseServiceImpl implements DataSource
|
|||
dataSource.setUpdateTime(now);
|
||||
try {
|
||||
dataSourceMapper.updateById(dataSource);
|
||||
log.info("Update datasource complete, datasourceId:{}, datasourceName:{}.", dataSource.getId(),
|
||||
dataSource.getName());
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return dataSource;
|
||||
} catch (DuplicateKeyException ex) {
|
||||
log.error("Update datasource error, datasourceId:{}, datasourceName:{}.", dataSource.getId(),
|
||||
dataSource.getName());
|
||||
putMsg(result, Status.DATASOURCE_EXIST);
|
||||
throw new ServiceException(Status.DATASOURCE_EXIST);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean checkName(String name) {
|
||||
|
|
@ -333,40 +304,29 @@ public class DataSourceServiceImpl extends BaseServiceImpl implements DataSource
|
|||
* @return true if data datasource not exists, otherwise return false
|
||||
*/
|
||||
@Override
|
||||
public Result<Object> verifyDataSourceName(String name) {
|
||||
Result<Object> result = new Result<>();
|
||||
public void verifyDataSourceName(String name) {
|
||||
List<DataSource> dataSourceList = dataSourceMapper.queryDataSourceByName(name);
|
||||
if (dataSourceList != null && !dataSourceList.isEmpty()) {
|
||||
log.warn("Datasource with the same name already exists, dataSourceName:{}.",
|
||||
dataSourceList.get(0).getName());
|
||||
putMsg(result, Status.DATASOURCE_EXIST);
|
||||
} else {
|
||||
putMsg(result, Status.SUCCESS);
|
||||
throw new ServiceException(Status.DATASOURCE_EXIST);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* check connection
|
||||
*
|
||||
* @param type data source type
|
||||
* @param type data source type
|
||||
* @param connectionParam connectionParam
|
||||
* @return true if connect successfully, otherwise false
|
||||
* @return true if connect successfully, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public Result<Object> checkConnection(DbType type, ConnectionParam connectionParam) {
|
||||
Result<Object> result = new Result<>();
|
||||
public void checkConnection(DbType type, ConnectionParam connectionParam) {
|
||||
DataSourceProcessor sshDataSourceProcessor = DataSourceUtils.getDatasourceProcessor(type);
|
||||
boolean connectivity = sshDataSourceProcessor.checkDataSourceConnectivity(connectionParam);
|
||||
if (connectivity) {
|
||||
putMsg(result, Status.SUCCESS);
|
||||
} else {
|
||||
putMsg(result, Status.CONNECTION_TEST_FAILURE);
|
||||
return;
|
||||
}
|
||||
log.info("Connection test to {} datasource success, connectionParam:{}", type.name(), connectionParam);
|
||||
return result;
|
||||
throw new ServiceException(Status.CONNECTION_TEST_FAILURE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -376,51 +336,36 @@ public class DataSourceServiceImpl extends BaseServiceImpl implements DataSource
|
|||
* @return connect result code
|
||||
*/
|
||||
@Override
|
||||
public Result<Object> connectionTest(int id) {
|
||||
public void connectionTest(int id) {
|
||||
DataSource dataSource = dataSourceMapper.selectById(id);
|
||||
if (dataSource == null) {
|
||||
Result<Object> result = new Result<>();
|
||||
log.error("Datasource does not exist, datasourceId:{}.", id);
|
||||
putMsg(result, Status.RESOURCE_NOT_EXIST);
|
||||
return result;
|
||||
throw new ServiceException(Status.RESOURCE_NOT_EXIST);
|
||||
}
|
||||
return checkConnection(dataSource.getType(),
|
||||
checkConnection(dataSource.getType(),
|
||||
DataSourceUtils.buildConnectionParams(dataSource.getType(), dataSource.getConnectionParams()));
|
||||
}
|
||||
|
||||
/**
|
||||
* delete datasource
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param loginUser login user
|
||||
* @param datasourceId data source id
|
||||
* @return delete result code
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public Result<Object> delete(User loginUser, int datasourceId) {
|
||||
Result<Object> result = new Result<>();
|
||||
try {
|
||||
// query datasource by id
|
||||
DataSource dataSource = dataSourceMapper.selectById(datasourceId);
|
||||
if (dataSource == null) {
|
||||
log.warn("Datasource does not exist, datasourceId:{}.", datasourceId);
|
||||
putMsg(result, Status.RESOURCE_NOT_EXIST);
|
||||
return result;
|
||||
}
|
||||
if (!canOperatorPermissions(loginUser, new Object[]{dataSource.getId()}, AuthorizationType.DATASOURCE,
|
||||
DATASOURCE_DELETE)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
}
|
||||
dataSourceMapper.deleteById(datasourceId);
|
||||
datasourceUserMapper.deleteByDatasourceId(datasourceId);
|
||||
log.info("Delete datasource complete, datasourceId:{}.", datasourceId);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
} catch (Exception e) {
|
||||
log.error("Delete datasource complete, datasourceId:{}.", datasourceId, e);
|
||||
throw new ServiceException(Status.DELETE_DATA_SOURCE_FAILURE);
|
||||
public void delete(User loginUser, int datasourceId) {
|
||||
// query datasource by id
|
||||
DataSource dataSource = dataSourceMapper.selectById(datasourceId);
|
||||
if (dataSource == null) {
|
||||
throw new ServiceException(Status.RESOURCE_NOT_EXIST);
|
||||
}
|
||||
return result;
|
||||
if (!canOperatorPermissions(loginUser, new Object[]{dataSource.getId()}, AuthorizationType.DATASOURCE,
|
||||
DATASOURCE_DELETE)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
dataSourceMapper.deleteById(datasourceId);
|
||||
datasourceUserMapper.deleteByDatasourceId(datasourceId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@
|
|||
package org.apache.dolphinscheduler.api.service.impl;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
|
||||
import org.apache.dolphinscheduler.api.service.DqExecuteResultService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.utils.DateUtils;
|
||||
import org.apache.dolphinscheduler.dao.entity.DqExecuteResult;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
|
@ -49,16 +49,15 @@ public class DqExecuteResultServiceImpl extends BaseServiceImpl implements DqExe
|
|||
private DqExecuteResultMapper dqExecuteResultMapper;
|
||||
|
||||
@Override
|
||||
public Result queryResultListPaging(User loginUser,
|
||||
String searchVal,
|
||||
Integer state,
|
||||
Integer ruleType,
|
||||
String startTime,
|
||||
String endTime,
|
||||
Integer pageNo,
|
||||
Integer pageSize) {
|
||||
public PageInfo<DqExecuteResult> queryResultListPaging(User loginUser,
|
||||
String searchVal,
|
||||
Integer state,
|
||||
Integer ruleType,
|
||||
String startTime,
|
||||
String endTime,
|
||||
Integer pageNo,
|
||||
Integer pageSize) {
|
||||
|
||||
Result result = new Result();
|
||||
int[] statusArray = null;
|
||||
// filter by state
|
||||
if (state != null) {
|
||||
|
|
@ -75,9 +74,7 @@ public class DqExecuteResultServiceImpl extends BaseServiceImpl implements DqExe
|
|||
end = DateUtils.stringToDate(endTime);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("Parameter startTime or endTime is invalid.");
|
||||
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, "startTime,endTime");
|
||||
return result;
|
||||
throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, "startTime,endTime");
|
||||
}
|
||||
|
||||
Page<DqExecuteResult> page = new Page<>(pageNo, pageSize);
|
||||
|
|
@ -99,8 +96,6 @@ public class DqExecuteResultServiceImpl extends BaseServiceImpl implements DqExe
|
|||
|
||||
pageInfo.setTotal((int) dqsResultPage.getTotal());
|
||||
pageInfo.setTotalList(dqsResultPage.getRecords());
|
||||
result.setData(pageInfo);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return pageInfo;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,14 +18,13 @@
|
|||
package org.apache.dolphinscheduler.api.service.impl;
|
||||
|
||||
import static org.apache.dolphinscheduler.common.constants.Constants.CHANGE;
|
||||
import static org.apache.dolphinscheduler.common.constants.Constants.DATA_LIST;
|
||||
import static org.apache.dolphinscheduler.common.constants.Constants.SMALL;
|
||||
|
||||
import org.apache.dolphinscheduler.api.dto.RuleDefinition;
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
|
||||
import org.apache.dolphinscheduler.api.service.DqRuleService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.utils.DateUtils;
|
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
||||
import org.apache.dolphinscheduler.dao.entity.DataSource;
|
||||
|
|
@ -59,9 +58,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -99,66 +96,44 @@ public class DqRuleServiceImpl extends BaseServiceImpl implements DqRuleService
|
|||
private DqComparisonTypeMapper dqComparisonTypeMapper;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getRuleFormCreateJsonById(int id) {
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public String getRuleFormCreateJsonById(int id) {
|
||||
|
||||
List<DqRuleInputEntry> ruleInputEntryList = dqRuleInputEntryMapper.getRuleInputEntryList(id);
|
||||
|
||||
if (ruleInputEntryList == null || ruleInputEntryList.isEmpty()) {
|
||||
putMsg(result, Status.QUERY_RULE_INPUT_ENTRY_LIST_ERROR);
|
||||
} else {
|
||||
result.put(DATA_LIST, getRuleFormCreateJson(DqRuleUtils.transformInputEntry(ruleInputEntryList)));
|
||||
putMsg(result, Status.SUCCESS);
|
||||
throw new ServiceException(Status.QUERY_RULE_INPUT_ENTRY_LIST_ERROR);
|
||||
}
|
||||
|
||||
return result;
|
||||
return getRuleFormCreateJson(DqRuleUtils.transformInputEntry(ruleInputEntryList));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAllRuleList() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
List<DqRule> ruleList =
|
||||
dqRuleMapper.selectList(new QueryWrapper<>());
|
||||
|
||||
result.put(DATA_LIST, ruleList);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
|
||||
return result;
|
||||
public List<DqRule> queryAllRuleList() {
|
||||
return dqRuleMapper.selectList(new QueryWrapper<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getDatasourceOptionsById(int datasourceId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public List<ParamsOptions> getDatasourceOptionsById(int datasourceId) {
|
||||
|
||||
List<DataSource> dataSourceList = dataSourceMapper.listAllDataSourceByType(datasourceId);
|
||||
List<ParamsOptions> options = null;
|
||||
if (CollectionUtils.isNotEmpty(dataSourceList)) {
|
||||
options = new ArrayList<>();
|
||||
|
||||
for (DataSource dataSource : dataSourceList) {
|
||||
ParamsOptions childrenOption =
|
||||
new ParamsOptions(dataSource.getName(), dataSource.getId(), false);
|
||||
options.add(childrenOption);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(dataSourceList)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
result.put(DATA_LIST, options);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
|
||||
return result;
|
||||
List<ParamsOptions> options = new ArrayList<>();
|
||||
for (DataSource dataSource : dataSourceList) {
|
||||
ParamsOptions childrenOption = new ParamsOptions(dataSource.getName(), dataSource.getId(), false);
|
||||
options.add(childrenOption);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result queryRuleListPaging(User loginUser,
|
||||
String searchVal,
|
||||
Integer ruleType,
|
||||
String startTime,
|
||||
String endTime,
|
||||
Integer pageNo,
|
||||
Integer pageSize) {
|
||||
Result result = new Result();
|
||||
public PageInfo<DqRule> queryRuleListPaging(User loginUser,
|
||||
String searchVal,
|
||||
Integer ruleType,
|
||||
String startTime,
|
||||
String endTime,
|
||||
Integer pageNo,
|
||||
Integer pageSize) {
|
||||
|
||||
Date start = null;
|
||||
Date end = null;
|
||||
|
|
@ -170,8 +145,7 @@ public class DqRuleServiceImpl extends BaseServiceImpl implements DqRuleService
|
|||
end = DateUtils.stringToDate(endTime);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, "startTime,endTime");
|
||||
return result;
|
||||
throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, "startTime,endTime");
|
||||
}
|
||||
|
||||
Page<DqRule> page = new Page<>(pageNo, pageSize);
|
||||
|
|
@ -203,9 +177,7 @@ public class DqRuleServiceImpl extends BaseServiceImpl implements DqRuleService
|
|||
pageInfo.setTotalList(dataList);
|
||||
}
|
||||
|
||||
result.setData(pageInfo);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
private String getRuleFormCreateJson(List<DqRuleInputEntry> ruleInputEntryList) {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationCon
|
|||
|
||||
import org.apache.dolphinscheduler.api.dto.EnvironmentDto;
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
|
||||
import org.apache.dolphinscheduler.api.service.EnvironmentService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
|
|
@ -95,28 +96,22 @@ public class EnvironmentServiceImpl extends BaseServiceImpl implements Environme
|
|||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public Map<String, Object> createEnvironment(User loginUser, String name, String config, String desc,
|
||||
String workerGroups) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public Long createEnvironment(User loginUser,
|
||||
String name,
|
||||
String config,
|
||||
String desc,
|
||||
String workerGroups) {
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.ENVIRONMENT, ENVIRONMENT_CREATE)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
if (checkDescriptionLength(desc)) {
|
||||
log.warn("Parameter description is too long.");
|
||||
putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
return result;
|
||||
}
|
||||
Map<String, Object> checkResult = checkParams(name, config, workerGroups);
|
||||
if (checkResult.get(Constants.STATUS) != Status.SUCCESS) {
|
||||
return checkResult;
|
||||
throw new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
}
|
||||
checkParams(name, config, workerGroups);
|
||||
|
||||
Environment environment = environmentMapper.queryByEnvironmentName(name);
|
||||
if (environment != null) {
|
||||
log.warn("Environment with the same name already exist, environmentName:{}.", environment.getName());
|
||||
putMsg(result, Status.ENVIRONMENT_NAME_EXISTS, name);
|
||||
return result;
|
||||
throw new ServiceException(Status.ENVIRONMENT_NAME_EXISTS, name);
|
||||
}
|
||||
|
||||
Environment env = new Environment();
|
||||
|
|
@ -134,8 +129,7 @@ public class EnvironmentServiceImpl extends BaseServiceImpl implements Environme
|
|||
log.error("Generate environment code error.", e);
|
||||
}
|
||||
if (code == 0L) {
|
||||
putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS, "Error generating environment code");
|
||||
return result;
|
||||
throw new ServiceException(Status.INTERNAL_SERVER_ERROR_ARGS, "Error generating environment code");
|
||||
}
|
||||
|
||||
if (environmentMapper.insert(env) > 0) {
|
||||
|
|
@ -159,16 +153,9 @@ public class EnvironmentServiceImpl extends BaseServiceImpl implements Environme
|
|||
});
|
||||
}
|
||||
}
|
||||
result.put(Constants.DATA_LIST, env.getCode());
|
||||
putMsg(result, Status.SUCCESS);
|
||||
permissionPostHandle(AuthorizationType.ENVIRONMENT, loginUser.getId(),
|
||||
Collections.singletonList(env.getId()), log);
|
||||
log.info("Environment create complete, name:{}.", env.getName());
|
||||
} else {
|
||||
log.error("Environment create error, name:{}.", env.getName());
|
||||
putMsg(result, Status.CREATE_ENVIRONMENT_ERROR);
|
||||
return env.getCode();
|
||||
}
|
||||
return result;
|
||||
throw new ServiceException(Status.CREATE_ENVIRONMENT_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -366,29 +353,20 @@ public class EnvironmentServiceImpl extends BaseServiceImpl implements Environme
|
|||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public Map<String, Object> updateEnvironmentByCode(User loginUser, Long code, String name, String config,
|
||||
String desc, String workerGroups) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public Environment updateEnvironmentByCode(User loginUser, Long code, String name, String config,
|
||||
String desc, String workerGroups) {
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.ENVIRONMENT, ENVIRONMENT_UPDATE)) {
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
Map<String, Object> checkResult = checkParams(name, config, workerGroups);
|
||||
if (checkResult.get(Constants.STATUS) != Status.SUCCESS) {
|
||||
return checkResult;
|
||||
}
|
||||
checkParams(name, config, workerGroups);
|
||||
if (checkDescriptionLength(desc)) {
|
||||
log.warn("Parameter description is too long.");
|
||||
putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
return result;
|
||||
throw new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
}
|
||||
|
||||
Environment environment = environmentMapper.queryByEnvironmentName(name);
|
||||
if (environment != null && !environment.getCode().equals(code)) {
|
||||
log.warn("Environment with the same name already exist, name:{}.", environment.getName());
|
||||
putMsg(result, Status.ENVIRONMENT_NAME_EXISTS, name);
|
||||
return result;
|
||||
throw new ServiceException(Status.ENVIRONMENT_NAME_EXISTS, name);
|
||||
}
|
||||
|
||||
Set<String> workerGroupSet;
|
||||
|
|
@ -402,17 +380,14 @@ public class EnvironmentServiceImpl extends BaseServiceImpl implements Environme
|
|||
Set<String> existWorkerGroupSet = relationMapper
|
||||
.queryByEnvironmentCode(code)
|
||||
.stream()
|
||||
.map(item -> item.getWorkerGroup())
|
||||
.map(EnvironmentWorkerGroupRelation::getWorkerGroup)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
Set<String> deleteWorkerGroupSet = SetUtils.difference(existWorkerGroupSet, workerGroupSet).toSet();
|
||||
Set<String> addWorkerGroupSet = SetUtils.difference(workerGroupSet, existWorkerGroupSet).toSet();
|
||||
|
||||
// verify whether the relation of this environment and worker groups can be adjusted
|
||||
checkResult = checkUsedEnvironmentWorkerGroupRelation(deleteWorkerGroupSet, name, code);
|
||||
if (checkResult.get(Constants.STATUS) != Status.SUCCESS) {
|
||||
return checkResult;
|
||||
}
|
||||
checkUsedEnvironmentWorkerGroupRelation(deleteWorkerGroupSet, name, code);
|
||||
|
||||
Environment env = new Environment();
|
||||
env.setCode(code);
|
||||
|
|
@ -424,33 +399,29 @@ public class EnvironmentServiceImpl extends BaseServiceImpl implements Environme
|
|||
|
||||
int update =
|
||||
environmentMapper.update(env, new UpdateWrapper<Environment>().lambda().eq(Environment::getCode, code));
|
||||
if (update > 0) {
|
||||
deleteWorkerGroupSet.stream().forEach(key -> {
|
||||
if (StringUtils.isNotEmpty(key)) {
|
||||
relationMapper.delete(new QueryWrapper<EnvironmentWorkerGroupRelation>()
|
||||
.lambda()
|
||||
.eq(EnvironmentWorkerGroupRelation::getEnvironmentCode, code)
|
||||
.eq(EnvironmentWorkerGroupRelation::getWorkerGroup, key));
|
||||
}
|
||||
});
|
||||
addWorkerGroupSet.stream().forEach(key -> {
|
||||
if (StringUtils.isNotEmpty(key)) {
|
||||
EnvironmentWorkerGroupRelation relation = new EnvironmentWorkerGroupRelation();
|
||||
relation.setEnvironmentCode(code);
|
||||
relation.setWorkerGroup(key);
|
||||
relation.setUpdateTime(new Date());
|
||||
relation.setCreateTime(new Date());
|
||||
relation.setOperator(loginUser.getId());
|
||||
relationMapper.insert(relation);
|
||||
}
|
||||
});
|
||||
log.info("Environment and relations update complete, environmentId:{}.", env.getId());
|
||||
putMsg(result, Status.SUCCESS);
|
||||
} else {
|
||||
log.error("Environment update error, environmentId:{}.", env.getId());
|
||||
putMsg(result, Status.UPDATE_ENVIRONMENT_ERROR, name);
|
||||
if (update <= 0) {
|
||||
throw new ServiceException(Status.UPDATE_ENVIRONMENT_ERROR, name);
|
||||
}
|
||||
return result;
|
||||
deleteWorkerGroupSet.forEach(key -> {
|
||||
if (StringUtils.isNotEmpty(key)) {
|
||||
relationMapper.delete(new QueryWrapper<EnvironmentWorkerGroupRelation>()
|
||||
.lambda()
|
||||
.eq(EnvironmentWorkerGroupRelation::getEnvironmentCode, code)
|
||||
.eq(EnvironmentWorkerGroupRelation::getWorkerGroup, key));
|
||||
}
|
||||
});
|
||||
addWorkerGroupSet.forEach(key -> {
|
||||
if (StringUtils.isNotEmpty(key)) {
|
||||
EnvironmentWorkerGroupRelation relation = new EnvironmentWorkerGroupRelation();
|
||||
relation.setEnvironmentCode(code);
|
||||
relation.setWorkerGroup(key);
|
||||
relation.setUpdateTime(new Date());
|
||||
relation.setCreateTime(new Date());
|
||||
relation.setOperator(loginUser.getId());
|
||||
relationMapper.insert(relation);
|
||||
}
|
||||
});
|
||||
return env;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -480,9 +451,8 @@ public class EnvironmentServiceImpl extends BaseServiceImpl implements Environme
|
|||
return result;
|
||||
}
|
||||
|
||||
private Map<String, Object> checkUsedEnvironmentWorkerGroupRelation(Set<String> deleteKeySet,
|
||||
String environmentName, Long environmentCode) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
private void checkUsedEnvironmentWorkerGroupRelation(Set<String> deleteKeySet,
|
||||
String environmentName, Long environmentCode) {
|
||||
for (String workerGroup : deleteKeySet) {
|
||||
List<TaskDefinition> taskDefinitionList = taskDefinitionMapper
|
||||
.selectList(new QueryWrapper<TaskDefinition>().lambda()
|
||||
|
|
@ -492,41 +462,26 @@ public class EnvironmentServiceImpl extends BaseServiceImpl implements Environme
|
|||
if (Objects.nonNull(taskDefinitionList) && taskDefinitionList.size() != 0) {
|
||||
Set<String> collect =
|
||||
taskDefinitionList.stream().map(TaskDefinition::getName).collect(Collectors.toSet());
|
||||
log.warn("Environment {} and worker group {} is being used by task {}, so can not update.",
|
||||
taskDefinitionList.get(0).getEnvironmentCode(), taskDefinitionList.get(0).getWorkerGroup(),
|
||||
collect);
|
||||
putMsg(result, Status.UPDATE_ENVIRONMENT_WORKER_GROUP_RELATION_ERROR, workerGroup, environmentName,
|
||||
collect);
|
||||
return result;
|
||||
throw new ServiceException(Status.UPDATE_ENVIRONMENT_WORKER_GROUP_RELATION_ERROR, workerGroup,
|
||||
environmentName, collect);
|
||||
}
|
||||
}
|
||||
result.put(Constants.STATUS, Status.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Map<String, Object> checkParams(String name, String config, String workerGroups) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
protected void checkParams(String name, String config, String workerGroups) {
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
log.warn("parameter environment name is empty.");
|
||||
putMsg(result, Status.ENVIRONMENT_NAME_IS_NULL);
|
||||
return result;
|
||||
throw new ServiceException(Status.ENVIRONMENT_NAME_IS_NULL);
|
||||
}
|
||||
if (StringUtils.isEmpty(config)) {
|
||||
log.warn("parameter environment config is empty.");
|
||||
putMsg(result, Status.ENVIRONMENT_CONFIG_IS_NULL);
|
||||
return result;
|
||||
throw new ServiceException(Status.ENVIRONMENT_CONFIG_IS_NULL);
|
||||
}
|
||||
if (!StringUtils.isEmpty(workerGroups)) {
|
||||
List<String> workerGroupList = JSONUtils.parseObject(workerGroups, new TypeReference<List<String>>() {
|
||||
});
|
||||
if (Objects.isNull(workerGroupList)) {
|
||||
log.warn("Parameter worker groups list is invalid.");
|
||||
putMsg(result, Status.ENVIRONMENT_WORKER_GROUPS_IS_INVALID);
|
||||
return result;
|
||||
throw new ServiceException(Status.ENVIRONMENT_WORKER_GROUPS_IS_INVALID);
|
||||
}
|
||||
}
|
||||
result.put(Constants.STATUS, Status.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -227,11 +227,9 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|||
boolean allLevelDependent, ExecutionOrder executionOrder) {
|
||||
Project project = projectMapper.queryByCode(projectCode);
|
||||
// check user access for project
|
||||
Map<String, Object> result =
|
||||
projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_START);
|
||||
if (result.get(Constants.STATUS) != Status.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_START);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
// timeout is invalid
|
||||
if (timeout <= 0 || timeout > MAX_TASK_TIMEOUT) {
|
||||
log.warn("Parameter timeout is invalid, timeout:{}.", timeout);
|
||||
|
|
@ -464,10 +462,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|||
|
||||
WorkflowExecuteResponse response = new WorkflowExecuteResponse();
|
||||
|
||||
Project project = projectMapper.queryByCode(projectCode);
|
||||
// check user access for project
|
||||
|
||||
projectService.checkProjectAndAuthThrowException(loginUser, project,
|
||||
projectService.checkProjectAndAuthThrowException(loginUser, projectCode,
|
||||
ApiFuncIdentificationConstant.map.get(ExecuteType.EXECUTE_TASK));
|
||||
|
||||
ProcessInstance processInstance = processService.findProcessInstanceDetailById(processInstanceId)
|
||||
|
|
@ -1158,18 +1154,15 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> execStreamTaskInstance(User loginUser, long projectCode, long taskDefinitionCode,
|
||||
int taskDefinitionVersion,
|
||||
int warningGroupId, String workerGroup, String tenantCode,
|
||||
Long environmentCode,
|
||||
Map<String, String> startParams, int dryRun) {
|
||||
public void execStreamTaskInstance(User loginUser, long projectCode, long taskDefinitionCode,
|
||||
int taskDefinitionVersion,
|
||||
int warningGroupId, String workerGroup, String tenantCode,
|
||||
Long environmentCode,
|
||||
Map<String, String> startParams, int dryRun) {
|
||||
Project project = projectMapper.queryByCode(projectCode);
|
||||
// check user access for project
|
||||
Map<String, Object> result =
|
||||
projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_START);
|
||||
if (result.get(Constants.STATUS) != Status.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_START);
|
||||
|
||||
checkValidTenant(tenantCode);
|
||||
checkMasterExists();
|
||||
// todo dispatch improvement
|
||||
|
|
@ -1195,13 +1188,11 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|||
streamingTaskOperator.triggerStreamingTask(taskExecuteStartMessage);
|
||||
if (streamingTaskTriggerResponse.isSuccess()) {
|
||||
log.info("Send task execute start command complete, response is {}.", streamingTaskOperator);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
} else {
|
||||
log.error(
|
||||
"Start to execute stream task instance error, projectCode:{}, taskDefinitionCode:{}, taskVersion:{}, response: {}.",
|
||||
projectCode, taskDefinitionCode, taskDefinitionVersion, streamingTaskTriggerResponse);
|
||||
putMsg(result, Status.START_TASK_INSTANCE_ERROR);
|
||||
return;
|
||||
}
|
||||
return result;
|
||||
log.error(
|
||||
"Start to execute stream task instance error, projectCode:{}, taskDefinitionCode:{}, taskVersion:{}, response: {}.",
|
||||
projectCode, taskDefinitionCode, taskDefinitionVersion, streamingTaskTriggerResponse);
|
||||
throw new ServiceException(Status.START_TASK_INSTANCE_ERROR);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.dolphinscheduler.api.service.impl;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
|
||||
import org.apache.dolphinscheduler.api.k8s.K8sClientService;
|
||||
import org.apache.dolphinscheduler.api.service.K8sNamespaceService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
|
|
@ -109,9 +110,8 @@ public class K8SNamespaceServiceImpl extends BaseServiceImpl implements K8sNames
|
|||
@Override
|
||||
public Map<String, Object> createK8sNamespace(User loginUser, String namespace, Long clusterCode) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (isNotAdmin(loginUser, result)) {
|
||||
log.warn("Only admin can create K8s namespace, current login user name:{}.", loginUser.getUserName());
|
||||
return result;
|
||||
if (isNotAdmin(loginUser)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(namespace)) {
|
||||
|
|
@ -220,9 +220,8 @@ public class K8SNamespaceServiceImpl extends BaseServiceImpl implements K8sNames
|
|||
@Override
|
||||
public Map<String, Object> deleteNamespaceById(User loginUser, int id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (isNotAdmin(loginUser, result)) {
|
||||
log.warn("Only admin can delete K8s namespace, current login user name:{}.", loginUser.getUserName());
|
||||
return result;
|
||||
if (isNotAdmin(loginUser)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
K8sNamespace k8sNamespaceObj = k8sNamespaceMapper.selectById(id);
|
||||
|
|
@ -258,8 +257,8 @@ public class K8SNamespaceServiceImpl extends BaseServiceImpl implements K8sNames
|
|||
@Override
|
||||
public Map<String, Object> queryUnauthorizedNamespace(User loginUser, Integer userId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (loginUser.getId() != userId && isNotAdmin(loginUser, result)) {
|
||||
return result;
|
||||
if (loginUser.getId() != userId && isNotAdmin(loginUser)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
// query all namespace list, this auth does not like project
|
||||
List<K8sNamespace> namespaceList = k8sNamespaceMapper.selectList(null);
|
||||
|
|
@ -286,8 +285,8 @@ public class K8SNamespaceServiceImpl extends BaseServiceImpl implements K8sNames
|
|||
public Map<String, Object> queryAuthorizedNamespace(User loginUser, Integer userId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
if (loginUser.getId() != userId && isNotAdmin(loginUser, result)) {
|
||||
return result;
|
||||
if (loginUser.getId() != userId && isNotAdmin(loginUser)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
List<K8sNamespace> namespaces = k8sNamespaceMapper.queryAuthedNamespaceListByUserId(userId);
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
|
@ -78,13 +77,13 @@ public class LoggerServiceImpl extends BaseServiceImpl implements LoggerService
|
|||
private TaskInstanceDao taskInstanceDao;
|
||||
|
||||
@Autowired
|
||||
ProjectMapper projectMapper;
|
||||
private ProjectMapper projectMapper;
|
||||
|
||||
@Autowired
|
||||
ProjectService projectService;
|
||||
private ProjectService projectService;
|
||||
|
||||
@Autowired
|
||||
TaskDefinitionMapper taskDefinitionMapper;
|
||||
private TaskDefinitionMapper taskDefinitionMapper;
|
||||
|
||||
/**
|
||||
* view log
|
||||
|
|
@ -148,28 +147,20 @@ public class LoggerServiceImpl extends BaseServiceImpl implements LoggerService
|
|||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> queryLog(User loginUser, long projectCode, int taskInstId, int skipLineNum, int limit) {
|
||||
Project project = projectMapper.queryByCode(projectCode);
|
||||
public String queryLog(User loginUser, long projectCode, int taskInstId, int skipLineNum, int limit) {
|
||||
// check user access for project
|
||||
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, projectCode, VIEW_LOG);
|
||||
if (result.get(Constants.STATUS) != Status.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
projectService.checkProjectAndAuthThrowException(loginUser, projectCode, VIEW_LOG);
|
||||
// check whether the task instance can be found
|
||||
TaskInstance task = taskInstanceDao.queryById(taskInstId);
|
||||
if (task == null || StringUtils.isBlank(task.getHost())) {
|
||||
putMsg(result, Status.TASK_INSTANCE_NOT_FOUND);
|
||||
return result;
|
||||
throw new ServiceException(Status.TASK_INSTANCE_NOT_FOUND);
|
||||
}
|
||||
|
||||
TaskDefinition taskDefinition = taskDefinitionMapper.queryByCode(task.getTaskCode());
|
||||
if (taskDefinition != null && projectCode != taskDefinition.getProjectCode()) {
|
||||
putMsg(result, Status.TASK_INSTANCE_NOT_FOUND, taskInstId);
|
||||
return result;
|
||||
throw new ServiceException(Status.TASK_INSTANCE_NOT_FOUND, taskInstId);
|
||||
}
|
||||
String log = queryLog(task, skipLineNum, limit);
|
||||
result.put(Constants.DATA_LIST, log);
|
||||
return result;
|
||||
return queryLog(task, skipLineNum, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -182,12 +173,9 @@ public class LoggerServiceImpl extends BaseServiceImpl implements LoggerService
|
|||
*/
|
||||
@Override
|
||||
public byte[] getLogBytes(User loginUser, long projectCode, int taskInstId) {
|
||||
Project project = projectMapper.queryByCode(projectCode);
|
||||
// check user access for project
|
||||
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, projectCode, DOWNLOAD_LOG);
|
||||
if (result.get(Constants.STATUS) != Status.SUCCESS) {
|
||||
throw new ServiceException("user has no permission");
|
||||
}
|
||||
projectService.checkProjectAndAuthThrowException(loginUser, projectCode, DOWNLOAD_LOG);
|
||||
|
||||
// check whether the task instance can be found
|
||||
TaskInstance task = taskInstanceDao.queryById(taskInstId);
|
||||
if (task == null || StringUtils.isBlank(task.getHost())) {
|
||||
|
|
|
|||
|
|
@ -17,20 +17,16 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service.impl;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.service.MonitorService;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.model.Server;
|
||||
import org.apache.dolphinscheduler.common.model.WorkerServerModel;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMetrics;
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMonitor;
|
||||
import org.apache.dolphinscheduler.registry.api.RegistryClient;
|
||||
import org.apache.dolphinscheduler.registry.api.enums.RegistryNodeType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -61,11 +57,8 @@ public class MonitorServiceImpl extends BaseServiceImpl implements MonitorServic
|
|||
* @return data base state
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> queryDatabaseState(User loginUser) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put(Constants.DATA_LIST, Lists.newArrayList(databaseMonitor.getDatabaseMetrics()));
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
public List<DatabaseMetrics> queryDatabaseState(User loginUser) {
|
||||
return Lists.newArrayList(databaseMonitor.getDatabaseMetrics());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -75,13 +68,8 @@ public class MonitorServiceImpl extends BaseServiceImpl implements MonitorServic
|
|||
* @return master information list
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> queryMaster(User loginUser) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
List<Server> masterServers = getServerListFromRegistry(true);
|
||||
result.put(Constants.DATA_LIST, masterServers);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
|
||||
return result;
|
||||
public List<Server> queryMaster(User loginUser) {
|
||||
return registryClient.getServerList(RegistryNodeType.MASTER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -91,10 +79,9 @@ public class MonitorServiceImpl extends BaseServiceImpl implements MonitorServic
|
|||
* @return worker information list
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> queryWorker(User loginUser) {
|
||||
public List<WorkerServerModel> queryWorker(User loginUser) {
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
List<WorkerServerModel> workerServers = getServerListFromRegistry(false)
|
||||
return registryClient.getServerList(RegistryNodeType.WORKER)
|
||||
.stream()
|
||||
.map((Server server) -> {
|
||||
WorkerServerModel model = new WorkerServerModel();
|
||||
|
|
@ -109,21 +96,6 @@ public class MonitorServiceImpl extends BaseServiceImpl implements MonitorServic
|
|||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Map<String, WorkerServerModel> workerHostPortServerMapping = workerServers
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
(WorkerServerModel worker) -> {
|
||||
String[] s = worker.getZkDirectories().iterator().next().split("/");
|
||||
return s[s.length - 1];
|
||||
}, Function.identity(), (WorkerServerModel oldOne, WorkerServerModel newOne) -> {
|
||||
oldOne.getZkDirectories().addAll(newOne.getZkDirectories());
|
||||
return oldOne;
|
||||
}));
|
||||
|
||||
result.put(Constants.DATA_LIST, workerHostPortServerMapping.values());
|
||||
putMsg(result, Status.SUCCESS);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ import org.apache.dolphinscheduler.dao.mapper.UserMapper;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
|
@ -142,8 +141,6 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
|
|||
log.info("Project is created and id is :{}", project.getId());
|
||||
result.setData(project);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
permissionPostHandle(AuthorizationType.PROJECTS, loginUser.getId(),
|
||||
Collections.singletonList(project.getId()), log);
|
||||
} else {
|
||||
log.error("Project create error, projectName:{}.", project.getName());
|
||||
putMsg(result, Status.CREATE_PROJECT_ERROR);
|
||||
|
|
@ -159,9 +156,8 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
|
|||
*/
|
||||
public static void checkDesc(Result result, String desc) {
|
||||
if (!StringUtils.isEmpty(desc) && desc.codePointCount(0, desc.length()) > 255) {
|
||||
log.warn("Parameter description check failed.");
|
||||
result.setCode(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getCode());
|
||||
result.setMsg(MessageFormat.format(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getMsg(), "desc length"));
|
||||
result.setCode(Status.DESCRIPTION_TOO_LONG_ERROR.getCode());
|
||||
result.setMsg(Status.DESCRIPTION_TOO_LONG_ERROR.getMsg());
|
||||
} else {
|
||||
result.setCode(Status.SUCCESS.getCode());
|
||||
}
|
||||
|
|
@ -319,6 +315,32 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
|
|||
return checkResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkHasProjectWritePermissionThrowException(User loginUser, long projectCode) {
|
||||
Project project = projectMapper.queryByCode(projectCode);
|
||||
checkHasProjectWritePermissionThrowException(loginUser, project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkHasProjectWritePermissionThrowException(User loginUser, Project project) {
|
||||
if (project == null) {
|
||||
throw new ServiceException(Status.PROJECT_NOT_FOUND, null);
|
||||
}
|
||||
// case 1: user is admin
|
||||
if (loginUser.getUserType() == UserType.ADMIN_USER) {
|
||||
return;
|
||||
}
|
||||
// case 2: user is project owner
|
||||
if (project.getUserId().equals(loginUser.getId())) {
|
||||
return;
|
||||
}
|
||||
// case 3: check user permission level
|
||||
ProjectUser projectUser = projectUserMapper.queryProjectRelation(project.getId(), loginUser.getId());
|
||||
if (projectUser == null || projectUser.getPerm() != Constants.DEFAULT_ADMIN_PERMISSION) {
|
||||
throw new ServiceException(Status.USER_NO_WRITE_PROJECT_PERM, loginUser.getUserName(), project.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasProjectAndPerm(User loginUser, Project project, Result result, String permission) {
|
||||
boolean checkResult = false;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import org.apache.dolphinscheduler.api.enums.Status;
|
|||
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
|
||||
import org.apache.dolphinscheduler.api.service.QueueService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
|
|
@ -40,11 +39,8 @@ import org.apache.commons.collections.CollectionUtils;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
|
|
@ -52,7 +48,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
|
@ -78,7 +73,7 @@ public class QueueServiceImpl extends BaseServiceImpl implements QueueService {
|
|||
*
|
||||
* @param queue The queue object want to create
|
||||
*/
|
||||
private void createQueueValid(Queue queue) throws ServiceException {
|
||||
private void validQueue(Queue queue) throws ServiceException {
|
||||
if (StringUtils.isEmpty(queue.getQueue())) {
|
||||
throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.QUEUE);
|
||||
} else if (StringUtils.isEmpty(queue.getQueueName())) {
|
||||
|
|
@ -125,91 +120,73 @@ public class QueueServiceImpl extends BaseServiceImpl implements QueueService {
|
|||
* @return queue list
|
||||
*/
|
||||
@Override
|
||||
public Result queryList(User loginUser) {
|
||||
Result result = new Result();
|
||||
public List<Queue> queryList(User loginUser) {
|
||||
Set<Integer> ids = resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.QUEUE,
|
||||
loginUser.getId(), log);
|
||||
if (loginUser.getUserType().equals(UserType.GENERAL_USER)) {
|
||||
ids = ids.isEmpty() ? new HashSet<>() : ids;
|
||||
ids.add(Constants.DEFAULT_QUEUE_ID);
|
||||
}
|
||||
List<Queue> queueList = queueMapper.selectBatchIds(ids);
|
||||
result.setData(queueList);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return queueMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* query queue list paging
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param pageNo page number
|
||||
* @param pageNo page number
|
||||
* @param searchVal search value
|
||||
* @param pageSize page size
|
||||
* @param pageSize page size
|
||||
* @return queue list
|
||||
*/
|
||||
@Override
|
||||
public Result queryList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) {
|
||||
Result result = new Result();
|
||||
public PageInfo<Queue> queryList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) {
|
||||
PageInfo<Queue> pageInfo = new PageInfo<>(pageNo, pageSize);
|
||||
Set<Integer> ids = resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.QUEUE,
|
||||
loginUser.getId(), log);
|
||||
if (ids.isEmpty()) {
|
||||
result.setData(pageInfo);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return pageInfo;
|
||||
}
|
||||
Page<Queue> page = new Page<>(pageNo, pageSize);
|
||||
IPage<Queue> queueList = queueMapper.queryQueuePaging(page, new ArrayList<>(ids), searchVal);
|
||||
Integer count = (int) queueList.getTotal();
|
||||
pageInfo.setTotal(count);
|
||||
pageInfo.setTotalList(queueList.getRecords());
|
||||
result.setData(pageInfo);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
|
||||
return result;
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* create queue
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param queue queue
|
||||
* @param queue queue
|
||||
* @param queueName queue name
|
||||
* @return create result
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public Result createQueue(User loginUser, String queue, String queueName) {
|
||||
Result result = new Result();
|
||||
public Queue createQueue(User loginUser, String queue, String queueName) {
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.QUEUE, YARN_QUEUE_CREATE)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
||||
Queue queueObj = new Queue(queueName, queue);
|
||||
createQueueValid(queueObj);
|
||||
validQueue(queueObj);
|
||||
queueMapper.insert(queueObj);
|
||||
|
||||
result.setData(queueObj);
|
||||
log.info("Queue create complete, queueName:{}.", queueObj.getQueueName());
|
||||
putMsg(result, Status.SUCCESS);
|
||||
permissionPostHandle(AuthorizationType.QUEUE, loginUser.getId(), Collections.singletonList(queueObj.getId()),
|
||||
log);
|
||||
return result;
|
||||
return queueObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* update queue
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param queue queue
|
||||
* @param id queue id
|
||||
* @param queue queue
|
||||
* @param id queue id
|
||||
* @param queueName queue name
|
||||
* @return update result code
|
||||
*/
|
||||
@Override
|
||||
public Result updateQueue(User loginUser, int id, String queue, String queueName) {
|
||||
Result result = new Result();
|
||||
public Queue updateQueue(User loginUser, int id, String queue, String queueName) {
|
||||
if (!canOperatorPermissions(loginUser, new Object[]{id}, AuthorizationType.QUEUE, YARN_QUEUE_UPDATE)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
|
|
@ -227,23 +204,19 @@ public class QueueServiceImpl extends BaseServiceImpl implements QueueService {
|
|||
}
|
||||
|
||||
queueMapper.updateById(updateQueue);
|
||||
result.setData(updateQueue);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return updateQueue;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete queue
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param id queue id
|
||||
* @param id queue id
|
||||
* @return delete result code
|
||||
* @throws Exception exception
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Map<String, Object> deleteQueueById(User loginUser, int id) throws Exception {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public void deleteQueueById(User loginUser, int id) throws Exception {
|
||||
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.TENANT, TENANT_DELETE)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
|
|
@ -268,15 +241,10 @@ public class QueueServiceImpl extends BaseServiceImpl implements QueueService {
|
|||
}
|
||||
|
||||
int delete = queueMapper.deleteById(id);
|
||||
if (delete > 0) {
|
||||
log.info("Queue is deleted and id is {}.", id);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
} else {
|
||||
log.error("Queue delete failed, queueId:{}.", id);
|
||||
putMsg(result, Status.DELETE_QUEUE_BY_ID_ERROR);
|
||||
if (delete <= 0) {
|
||||
throw new ServiceException(Status.DELETE_QUEUE_BY_ID_ERROR);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -287,14 +255,9 @@ public class QueueServiceImpl extends BaseServiceImpl implements QueueService {
|
|||
* @return true if the queue name not exists, otherwise return false
|
||||
*/
|
||||
@Override
|
||||
public Result<Object> verifyQueue(String queue, String queueName) {
|
||||
Result<Object> result = new Result<>();
|
||||
|
||||
public void verifyQueue(String queue, String queueName) {
|
||||
Queue queueValidator = new Queue(queueName, queue);
|
||||
createQueueValid(queueValidator);
|
||||
result.setData(queueValidator);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
validQueue(queueValidator);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -349,7 +312,7 @@ public class QueueServiceImpl extends BaseServiceImpl implements QueueService {
|
|||
return existsQueue;
|
||||
}
|
||||
Queue queueObj = new Queue(queueName, queue);
|
||||
createQueueValid(queueObj);
|
||||
validQueue(queueObj);
|
||||
queueMapper.insert(queueObj);
|
||||
log.info("Queue create complete, queueName:{}.", queueObj.getQueueName());
|
||||
return queueObj;
|
||||
|
|
|
|||
|
|
@ -1218,40 +1218,6 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe
|
|||
return storageOperate.getFileStatus(fullName, defaultPath, user.getTenantCode(), ResourceType.FILE);
|
||||
}
|
||||
|
||||
private void permissionPostHandle(ResourceType resourceType, User loginUser, Integer resourceId) {
|
||||
AuthorizationType authorizationType =
|
||||
resourceType.equals(ResourceType.FILE) ? AuthorizationType.RESOURCE_FILE_ID
|
||||
: AuthorizationType.UDF_FILE;
|
||||
permissionPostHandle(authorizationType, loginUser.getId(), Collections.singletonList(resourceId), log);
|
||||
}
|
||||
|
||||
private Result<Object> verifyResource(User loginUser, ResourceType type, String fullName, int pid) {
|
||||
Result<Object> result = verifyResourceName(fullName, type, loginUser);
|
||||
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
|
||||
return result;
|
||||
}
|
||||
return verifyPid(loginUser, pid);
|
||||
}
|
||||
|
||||
private Result<Object> verifyPid(User loginUser, int pid) {
|
||||
Result<Object> result = new Result<>();
|
||||
putMsg(result, Status.SUCCESS);
|
||||
if (pid != -1) {
|
||||
Resource parentResource = resourcesMapper.selectById(pid);
|
||||
if (parentResource == null) {
|
||||
log.error("Parent resource does not exist, parentResourceId:{}.", pid);
|
||||
putMsg(result, Status.PARENT_RESOURCE_NOT_EXIST);
|
||||
return result;
|
||||
}
|
||||
if (!canOperator(loginUser, parentResource.getUserId())) {
|
||||
log.warn("User does not have operation privilege, loginUserName:{}.", loginUser.getUserName());
|
||||
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* updateProcessInstance resource
|
||||
*
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ import org.apache.commons.collections4.CollectionUtils;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
|
@ -129,8 +128,6 @@ public class TaskGroupServiceImpl extends BaseServiceImpl implements TaskGroupSe
|
|||
.build();
|
||||
|
||||
if (taskGroupMapper.insert(taskGroup) > 0) {
|
||||
permissionPostHandle(AuthorizationType.TASK_GROUP, loginUser.getId(),
|
||||
Collections.singletonList(taskGroup.getId()), log);
|
||||
log.info("Create task group complete, taskGroupName:{}.", taskGroup.getName());
|
||||
putMsg(result, Status.SUCCESS);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import org.apache.dolphinscheduler.api.service.QueueService;
|
|||
import org.apache.dolphinscheduler.api.service.TenantService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.RegexUtils;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
|
||||
|
|
@ -141,30 +140,22 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService
|
|||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Map<String, Object> createTenant(User loginUser,
|
||||
String tenantCode,
|
||||
int queueId,
|
||||
String desc) throws Exception {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put(Constants.STATUS, false);
|
||||
public Tenant createTenant(User loginUser,
|
||||
String tenantCode,
|
||||
int queueId,
|
||||
String desc) throws Exception {
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.TENANT, TENANT_CREATE)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
if (checkDescriptionLength(desc)) {
|
||||
log.warn("Parameter description is too long.");
|
||||
putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
return result;
|
||||
throw new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
}
|
||||
Tenant tenant = new Tenant(tenantCode, desc, queueId);
|
||||
createTenantValid(tenant);
|
||||
tenantMapper.insert(tenant);
|
||||
|
||||
storageOperate.createTenantDirIfNotExists(tenantCode);
|
||||
permissionPostHandle(AuthorizationType.TENANT, loginUser.getId(), Collections.singletonList(tenant.getId()),
|
||||
log);
|
||||
result.put(Constants.DATA_LIST, tenant);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -177,25 +168,16 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService
|
|||
* @return tenant list page
|
||||
*/
|
||||
@Override
|
||||
public Result<Object> queryTenantList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) {
|
||||
public PageInfo<Tenant> queryTenantList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) {
|
||||
|
||||
Result<Object> result = new Result<>();
|
||||
PageInfo<Tenant> pageInfo = new PageInfo<>(pageNo, pageSize);
|
||||
Set<Integer> ids = resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.TENANT,
|
||||
loginUser.getId(), log);
|
||||
if (ids.isEmpty()) {
|
||||
result.setData(pageInfo);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return new PageInfo<>(pageNo, pageSize);
|
||||
}
|
||||
Page<Tenant> page = new Page<>(pageNo, pageSize);
|
||||
IPage<Tenant> tenantPage = tenantMapper.queryTenantPaging(page, new ArrayList<>(ids), searchVal);
|
||||
|
||||
pageInfo.setTotal((int) tenantPage.getTotal());
|
||||
pageInfo.setTotalList(tenantPage.getRecords());
|
||||
result.setData(pageInfo);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return PageInfo.of(tenantPage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -210,51 +192,45 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService
|
|||
* @throws Exception exception
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> updateTenant(User loginUser, int id, String tenantCode, int queueId,
|
||||
String desc) throws Exception {
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public void updateTenant(User loginUser,
|
||||
int id,
|
||||
String tenantCode,
|
||||
int queueId,
|
||||
String desc) throws Exception {
|
||||
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.TENANT, TENANT_UPDATE)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
}
|
||||
if (checkDescriptionLength(desc)) {
|
||||
log.warn("Parameter description is too long.");
|
||||
putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
return result;
|
||||
throw new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR);
|
||||
}
|
||||
Tenant updateTenant = new Tenant(id, tenantCode, desc, queueId);
|
||||
Tenant existsTenant = tenantMapper.queryById(id);
|
||||
updateTenantValid(existsTenant, updateTenant);
|
||||
|
||||
updateTenant.setCreateTime(existsTenant.getCreateTime());
|
||||
// updateProcessInstance tenant
|
||||
// if the tenant code is modified, the original resource needs to be copied to the new tenant.
|
||||
if (!Objects.equals(existsTenant.getTenantCode(), updateTenant.getTenantCode())) {
|
||||
storageOperate.createTenantDirIfNotExists(tenantCode);
|
||||
}
|
||||
int update = tenantMapper.updateById(updateTenant);
|
||||
if (update > 0) {
|
||||
log.info("Tenant is updated and id is {}.", updateTenant.getId());
|
||||
putMsg(result, Status.SUCCESS);
|
||||
} else {
|
||||
log.error("Tenant update error, id:{}.", updateTenant.getId());
|
||||
putMsg(result, Status.UPDATE_TENANT_ERROR);
|
||||
if (update <= 0) {
|
||||
throw new ServiceException(Status.UPDATE_TENANT_ERROR);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete tenant
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param id tenant id
|
||||
* @param id tenant id
|
||||
* @return delete result code
|
||||
* @throws Exception exception
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Map<String, Object> deleteTenantById(User loginUser, int id) throws Exception {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
@Transactional()
|
||||
public void deleteTenantById(User loginUser, int id) throws Exception {
|
||||
|
||||
if (!canOperatorPermissions(loginUser, null, AuthorizationType.TENANT, TENANT_DELETE)) {
|
||||
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
|
||||
|
|
@ -262,44 +238,31 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService
|
|||
|
||||
Tenant tenant = tenantMapper.queryById(id);
|
||||
if (Objects.isNull(tenant)) {
|
||||
log.error("Tenant does not exist, userId:{}.", id);
|
||||
throw new ServiceException(Status.TENANT_NOT_EXIST);
|
||||
}
|
||||
|
||||
List<ProcessInstance> processInstances = getProcessInstancesByTenant(tenant);
|
||||
if (CollectionUtils.isNotEmpty(processInstances)) {
|
||||
log.warn("Delete tenant failed, because there are {} executing process instances using it.",
|
||||
processInstances.size());
|
||||
throw new ServiceException(Status.DELETE_TENANT_BY_ID_FAIL, processInstances.size());
|
||||
}
|
||||
|
||||
List<Schedule> schedules =
|
||||
scheduleMapper.queryScheduleListByTenant(tenant.getTenantCode());
|
||||
List<Schedule> schedules = scheduleMapper.queryScheduleListByTenant(tenant.getTenantCode());
|
||||
if (CollectionUtils.isNotEmpty(schedules)) {
|
||||
log.warn("Delete tenant failed, because there are {} schedule using it.",
|
||||
schedules.size());
|
||||
throw new ServiceException(Status.DELETE_TENANT_BY_ID_FAIL_DEFINES, schedules.size());
|
||||
}
|
||||
|
||||
List<User> userList = userMapper.queryUserListByTenant(tenant.getId());
|
||||
if (CollectionUtils.isNotEmpty(userList)) {
|
||||
log.warn("Delete tenant failed, because there are {} users using it.", userList.size());
|
||||
throw new ServiceException(Status.DELETE_TENANT_BY_ID_FAIL_USERS, userList.size());
|
||||
}
|
||||
|
||||
storageOperate.deleteTenant(tenant.getTenantCode());
|
||||
|
||||
int delete = tenantMapper.deleteById(id);
|
||||
if (delete > 0) {
|
||||
processInstanceMapper.updateProcessInstanceByTenantCode(tenant.getTenantCode(), Constants.DEFAULT);
|
||||
log.info("Tenant is deleted and id is {}.", id);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
} else {
|
||||
log.error("Tenant delete failed, tenantId:{}.", id);
|
||||
putMsg(result, Status.DELETE_TENANT_BY_ID_ERROR);
|
||||
if (delete <= 0) {
|
||||
throw new ServiceException(Status.DELETE_TENANT_BY_ID_ERROR);
|
||||
}
|
||||
|
||||
return result;
|
||||
processInstanceMapper.updateProcessInstanceByTenantCode(tenant.getTenantCode(), Constants.DEFAULT);
|
||||
storageOperate.deleteTenant(tenant.getTenantCode());
|
||||
}
|
||||
|
||||
private List<ProcessInstance> getProcessInstancesByTenant(Tenant tenant) {
|
||||
|
|
@ -314,20 +277,14 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService
|
|||
* @return tenant list
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> queryTenantList(User loginUser) {
|
||||
public List<Tenant> queryTenantList(User loginUser) {
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Set<Integer> ids = resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.TENANT,
|
||||
loginUser.getId(), log);
|
||||
if (ids.isEmpty()) {
|
||||
result.put(Constants.DATA_LIST, Collections.emptyList());
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Tenant> resourceList = tenantMapper.selectBatchIds(ids);
|
||||
result.put(Constants.DATA_LIST, resourceList);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return tenantMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -337,13 +294,10 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService
|
|||
* @return true if tenant code can use, otherwise return false
|
||||
*/
|
||||
@Override
|
||||
public Result<Object> verifyTenantCode(String tenantCode) {
|
||||
Result<Object> result = new Result<>();
|
||||
public void verifyTenantCode(String tenantCode) {
|
||||
if (checkTenantExists(tenantCode)) {
|
||||
throw new ServiceException(Status.OS_TENANT_CODE_EXIST, tenantCode);
|
||||
}
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -148,7 +148,6 @@ public class UdfFuncServiceImpl extends BaseServiceImpl implements UdfFuncServic
|
|||
udfFuncMapper.insert(udf);
|
||||
log.info("UDF function create complete, udfFuncName:{}.", udf.getFuncName());
|
||||
putMsg(result, Status.SUCCESS);
|
||||
permissionPostHandle(AuthorizationType.UDF, loginUser.getId(), Collections.singletonList(udf.getId()), log);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.api.service.impl;
|
|||
import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.TASK_TYPE_DEPENDENT;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
|
||||
import org.apache.dolphinscheduler.api.service.WorkFlowLineageService;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
||||
|
|
@ -78,39 +79,28 @@ public class WorkFlowLineageServiceImpl extends BaseServiceImpl implements WorkF
|
|||
private TaskDefinitionMapper taskDefinitionMapper;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryWorkFlowLineageByName(long projectCode, String workFlowName) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
public List<WorkFlowLineage> queryWorkFlowLineageByName(long projectCode, String workFlowName) {
|
||||
Project project = projectMapper.queryByCode(projectCode);
|
||||
if (project == null) {
|
||||
log.error("Project does not exist, projectCode:{}.", projectCode);
|
||||
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode);
|
||||
return result;
|
||||
throw new ServiceException(Status.PROJECT_NOT_FOUND, projectCode);
|
||||
}
|
||||
List<WorkFlowLineage> workFlowLineageList =
|
||||
workFlowLineageMapper.queryWorkFlowLineageByName(projectCode, workFlowName);
|
||||
result.put(Constants.DATA_LIST, workFlowLineageList);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return workFlowLineageMapper.queryWorkFlowLineageByName(projectCode, workFlowName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryWorkFlowLineageByCode(long projectCode, long sourceWorkFlowCode) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Project project = projectMapper.queryByCode(projectCode);
|
||||
if (project == null) {
|
||||
log.error("Project does not exist, projectCode:{}.", projectCode);
|
||||
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode);
|
||||
return result;
|
||||
throw new ServiceException(Status.PROJECT_NOT_FOUND, projectCode);
|
||||
}
|
||||
List<WorkFlowLineage> workFlowLineages = new ArrayList<>();
|
||||
Set<WorkFlowRelation> workFlowRelations = new HashSet<>();
|
||||
recursiveWorkFlow(projectCode, sourceWorkFlowCode, workFlowLineages, workFlowRelations);
|
||||
Map<String, Object> workFlowLists = new HashMap<>();
|
||||
// todo: use vo
|
||||
workFlowLists.put(Constants.WORKFLOW_LIST, workFlowLineages);
|
||||
workFlowLists.put(Constants.WORKFLOW_RELATION_LIST, workFlowRelations);
|
||||
result.put(Constants.DATA_LIST, workFlowLists);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
return workFlowLists;
|
||||
}
|
||||
|
||||
private void recursiveWorkFlow(long projectCode,
|
||||
|
|
|
|||
|
|
@ -166,8 +166,6 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
|
|||
workerGroupMapper.updateById(workerGroup);
|
||||
} else {
|
||||
workerGroupMapper.insert(workerGroup);
|
||||
permissionPostHandle(AuthorizationType.WORKER_GROUP, loginUser.getId(),
|
||||
Collections.singletonList(workerGroup.getId()), log);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,11 +20,11 @@ package org.apache.dolphinscheduler.api.utils;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* page info
|
||||
*
|
||||
* @param <T> model
|
||||
*/
|
||||
import lombok.Data;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
@Data
|
||||
public class PageInfo<T> {
|
||||
|
||||
/**
|
||||
|
|
@ -65,67 +65,14 @@ public class PageInfo<T> {
|
|||
this.currentPage = currentPage;
|
||||
}
|
||||
|
||||
public Integer getStart() {
|
||||
return pageNo;
|
||||
public static <T> PageInfo<T> of(IPage<T> iPage) {
|
||||
PageInfo<T> pageInfo = new PageInfo<>((int) iPage.getCurrent(), (int) iPage.getSize());
|
||||
pageInfo.setTotalList(iPage.getRecords());
|
||||
pageInfo.setTotal((int) iPage.getTotal());
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
public void setStart(Integer start) {
|
||||
this.pageNo = start;
|
||||
}
|
||||
|
||||
public List<T> getTotalList() {
|
||||
return totalList;
|
||||
}
|
||||
|
||||
public void setTotalList(List<T> totalList) {
|
||||
this.totalList = totalList;
|
||||
}
|
||||
|
||||
public Integer getTotal() {
|
||||
if (total == null) {
|
||||
total = 0;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(Integer total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public Integer getTotalPage() {
|
||||
if (pageSize == null || pageSize == 0) {
|
||||
pageSize = 7;
|
||||
}
|
||||
this.totalPage =
|
||||
(this.total % this.pageSize) == 0
|
||||
? ((this.total / this.pageSize) == 0 ? 1 : (this.total / this.pageSize))
|
||||
: (this.total / this.pageSize + 1);
|
||||
return this.totalPage;
|
||||
}
|
||||
|
||||
public void setTotalPage(Integer totalPage) {
|
||||
this.totalPage = totalPage;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
if (pageSize == null || pageSize == 0) {
|
||||
pageSize = 7;
|
||||
}
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public Integer getCurrentPage() {
|
||||
if (currentPage == null || currentPage <= 0) {
|
||||
this.currentPage = 1;
|
||||
}
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
public void setCurrentPage(Integer currentPage) {
|
||||
this.currentPage = currentPage;
|
||||
public static <T> PageInfo<T> of(Integer currentPage, Integer pageSize) {
|
||||
return new PageInfo<>(currentPage, pageSize);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,28 +15,23 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.api.dto;
|
||||
package org.apache.dolphinscheduler.api;
|
||||
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.dao.entity.AccessToken;
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
|
||||
|
||||
public class CreateTokenResponse extends Result {
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
|
||||
private AccessToken data;
|
||||
public class AssertionsHelper extends Assertions {
|
||||
|
||||
public CreateTokenResponse(Result result) {
|
||||
super();
|
||||
this.setCode(result.getCode());
|
||||
this.setMsg(result.getMsg());
|
||||
this.setData((AccessToken) result.getData());
|
||||
public static void assertThrowsServiceException(Status status, Executable executable) {
|
||||
ServiceException exception = Assertions.assertThrows(ServiceException.class, executable);
|
||||
Assertions.assertEquals(status.getCode(), exception.getCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessToken getData() {
|
||||
return data;
|
||||
public static void assertDoesNotThrow(Executable executable) {
|
||||
Assertions.assertDoesNotThrow(executable);
|
||||
}
|
||||
|
||||
public void setData(AccessToken data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
|
@ -90,7 +90,7 @@ public class AccessTokenControllerTest extends AbstractControllerTest {
|
|||
MvcResult mvcResult = mockMvc.perform(post("/access-tokens")
|
||||
.header("sessionId", sessionId)
|
||||
.params(paramsMap))
|
||||
.andExpect(status().isCreated())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andReturn();
|
||||
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
|
|
|
|||
|
|
@ -91,11 +91,11 @@ public class AccessTokenV2ControllerTest extends AbstractControllerTest {
|
|||
.header("sessionId", sessionId)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(JSONUtils.toJsonString(paramsMap)))
|
||||
.andExpect(status().isCreated())
|
||||
// todo: bad request?
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andReturn();
|
||||
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
Assertions.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getCode(), result.getCode().intValue());
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.api.controller;
|
|||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
|
|
@ -28,10 +29,9 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
|||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.service.AlertPluginInstanceService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.AlertPluginInstanceType;
|
||||
import org.apache.dolphinscheduler.common.enums.WarningType;
|
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
||||
|
|
@ -44,8 +44,6 @@ import org.springframework.test.web.servlet.MvcResult;
|
|||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* alert plugin instance controller test
|
||||
*/
|
||||
|
|
@ -57,9 +55,7 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
|
|||
private static final AlertPluginInstanceType pluginInstanceType = AlertPluginInstanceType.NORMAL;
|
||||
private static final WarningType warningType = WarningType.ALL;
|
||||
private static final Result expectResponseContent = JSONUtils.parseObject(
|
||||
"{\"code\":0,\"msg\":\"success\",\"data\":\"Test Data\",\"success\":true,\"failed\":false}", Result.class);
|
||||
private static final ImmutableMap<String, Object> alertPluginInstanceServiceResult =
|
||||
ImmutableMap.of(Constants.STATUS, Status.SUCCESS, Constants.DATA_LIST, "Test Data");
|
||||
"{\"code\":0,\"msg\":\"success\",\"data\":\"null\",\"success\":true,\"failed\":false}", Result.class);
|
||||
|
||||
@MockBean(name = "alertPluginInstanceServiceImpl")
|
||||
private AlertPluginInstanceService alertPluginInstanceService;
|
||||
|
|
@ -75,8 +71,7 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
|
|||
paramsMap.add("pluginInstanceParams", pluginInstanceParams);
|
||||
|
||||
when(alertPluginInstanceService.create(any(User.class), eq(pluginDefineId), eq(instanceName),
|
||||
eq(pluginInstanceType), eq(warningType), eq(pluginInstanceParams)))
|
||||
.thenReturn(alertPluginInstanceServiceResult);
|
||||
eq(pluginInstanceType), eq(warningType), eq(pluginInstanceParams))).thenReturn(null);
|
||||
|
||||
// When
|
||||
final MvcResult mvcResult = mockMvc.perform(post("/alert-plugin-instances")
|
||||
|
|
@ -89,22 +84,18 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
|
|||
// Then
|
||||
final Result actualResponseContent =
|
||||
JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
assertThat(actualResponseContent.toString()).isEqualTo(expectResponseContent.toString());
|
||||
assertThat(actualResponseContent.getMsg()).isEqualTo(expectResponseContent.getMsg());
|
||||
assertThat(actualResponseContent.getCode()).isEqualTo(expectResponseContent.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendAlertPluginInstance() throws Exception {
|
||||
// Given
|
||||
Result result = JSONUtils.parseObject(
|
||||
"{\"code\":0,\"msg\":\"success\",\"data\":\"Test Data\",\"success\":true,\"failed\":false}",
|
||||
Result.class);
|
||||
|
||||
final MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
|
||||
paramsMap.add("pluginDefineId", String.valueOf(pluginDefineId));
|
||||
paramsMap.add("pluginInstanceParams", pluginInstanceParams);
|
||||
|
||||
when(alertPluginInstanceService.testSend(eq(pluginDefineId), eq(pluginInstanceParams)))
|
||||
.thenReturn(result);
|
||||
doNothing().when(alertPluginInstanceService).testSend(eq(pluginDefineId), eq(pluginInstanceParams));
|
||||
|
||||
// When
|
||||
final MvcResult mvcResult = mockMvc.perform(post("/alert-plugin-instances/test-send")
|
||||
|
|
@ -117,7 +108,8 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
|
|||
// Then
|
||||
final Result actualResponseContent =
|
||||
JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
assertThat(actualResponseContent.toString()).isEqualTo(expectResponseContent.toString());
|
||||
assertThat(actualResponseContent.getMsg()).isEqualTo(expectResponseContent.getMsg());
|
||||
assertThat(actualResponseContent.getCode()).isEqualTo(expectResponseContent.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -129,9 +121,8 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
|
|||
paramsMap.add("warningType", warningType.name());
|
||||
paramsMap.add("pluginInstanceParams", pluginInstanceParams);
|
||||
|
||||
when(alertPluginInstanceService.update(any(User.class), eq(pluginDefineId), eq(instanceName),
|
||||
eq(warningType), eq(pluginInstanceParams)))
|
||||
.thenReturn(alertPluginInstanceServiceResult);
|
||||
when(alertPluginInstanceService.updateById(any(User.class), eq(pluginDefineId), eq(instanceName),
|
||||
eq(warningType), eq(pluginInstanceParams))).thenReturn(null);
|
||||
|
||||
// When
|
||||
final MvcResult mvcResult = mockMvc.perform(put("/alert-plugin-instances/{id}", pluginDefineId)
|
||||
|
|
@ -144,7 +135,8 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
|
|||
// Then
|
||||
final Result actualResponseContent =
|
||||
JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
assertThat(actualResponseContent.toString()).isEqualTo(expectResponseContent.toString());
|
||||
assertThat(actualResponseContent.getMsg()).isEqualTo(expectResponseContent.getMsg());
|
||||
assertThat(actualResponseContent.getCode()).isEqualTo(expectResponseContent.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -155,8 +147,7 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
|
|||
paramsMap.add("instanceName", instanceName);
|
||||
paramsMap.add("pluginInstanceParams", pluginInstanceParams);
|
||||
|
||||
when(alertPluginInstanceService.delete(any(User.class), eq(pluginDefineId)))
|
||||
.thenReturn(alertPluginInstanceServiceResult);
|
||||
doNothing().when(alertPluginInstanceService).deleteById(any(User.class), eq(pluginDefineId));
|
||||
|
||||
// When
|
||||
final MvcResult mvcResult = mockMvc.perform(delete("/alert-plugin-instances/{id}", pluginDefineId)
|
||||
|
|
@ -169,7 +160,8 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
|
|||
// Then
|
||||
final Result actualResponseContent =
|
||||
JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
assertThat(actualResponseContent.toString()).isEqualTo(expectResponseContent.toString());
|
||||
assertThat(actualResponseContent.getMsg()).isEqualTo(expectResponseContent.getMsg());
|
||||
assertThat(actualResponseContent.getCode()).isEqualTo(expectResponseContent.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -178,8 +170,7 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
|
|||
final MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
|
||||
paramsMap.add("pluginDefineId", String.valueOf(pluginDefineId));
|
||||
|
||||
when(alertPluginInstanceService.get(any(User.class), eq(pluginDefineId)))
|
||||
.thenReturn(alertPluginInstanceServiceResult);
|
||||
when(alertPluginInstanceService.getById(any(User.class), eq(pluginDefineId))).thenReturn(null);
|
||||
|
||||
// When
|
||||
final MvcResult mvcResult = mockMvc.perform(get("/alert-plugin-instances/{id}", pluginDefineId)
|
||||
|
|
@ -192,14 +183,14 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
|
|||
// Then
|
||||
final Result actualResponseContent =
|
||||
JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
assertThat(actualResponseContent.toString()).isEqualTo(expectResponseContent.toString());
|
||||
assertThat(actualResponseContent.getMsg()).isEqualTo(expectResponseContent.getMsg());
|
||||
assertThat(actualResponseContent.getCode()).isEqualTo(expectResponseContent.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAlertPluginInstanceList() throws Exception {
|
||||
// Given
|
||||
when(alertPluginInstanceService.queryAll())
|
||||
.thenReturn(alertPluginInstanceServiceResult);
|
||||
when(alertPluginInstanceService.queryAll()).thenReturn(null);
|
||||
|
||||
// When
|
||||
final MvcResult mvcResult = mockMvc.perform(get("/alert-plugin-instances/list")
|
||||
|
|
@ -211,7 +202,8 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
|
|||
// Then
|
||||
final Result actualResponseContent =
|
||||
JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
assertThat(actualResponseContent.toString()).isEqualTo(expectResponseContent.toString());
|
||||
assertThat(actualResponseContent.getMsg()).isEqualTo(expectResponseContent.getMsg());
|
||||
assertThat(actualResponseContent.getCode()).isEqualTo(expectResponseContent.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -238,7 +230,8 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
|
|||
// Then
|
||||
final Result actualResponseContent =
|
||||
JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
assertThat(actualResponseContent.toString()).isEqualTo(expectResponseContent.toString());
|
||||
assertThat(actualResponseContent.getMsg()).isEqualTo(expectResponseContent.getMsg());
|
||||
assertThat(actualResponseContent.getCode()).isEqualTo(expectResponseContent.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -266,16 +259,13 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
|
|||
// Then
|
||||
final Result actualResponseContent =
|
||||
JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
assertThat(actualResponseContent.toString()).isEqualTo(expectResponseContent.toString());
|
||||
assertThat(actualResponseContent.getMsg()).isEqualTo(expectResponseContent.getMsg());
|
||||
assertThat(actualResponseContent.getCode()).isEqualTo(expectResponseContent.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListPaging() throws Exception {
|
||||
// Given
|
||||
Result result = JSONUtils.parseObject(
|
||||
"{\"code\":0,\"msg\":\"success\",\"data\":\"Test Data\",\"success\":true,\"failed\":false}",
|
||||
Result.class);
|
||||
|
||||
final MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
|
||||
paramsMap.add("pluginDefineId", String.valueOf(pluginDefineId));
|
||||
paramsMap.add("searchVal", "searchVal");
|
||||
|
|
@ -283,7 +273,7 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
|
|||
paramsMap.add("pageSize", String.valueOf(10));
|
||||
|
||||
when(alertPluginInstanceService.listPaging(eq(user), eq("searchVal"), eq(1), eq(10)))
|
||||
.thenReturn(result);
|
||||
.thenReturn(PageInfo.of(1, 10));
|
||||
|
||||
// When
|
||||
final MvcResult mvcResult = mockMvc.perform(get("/alert-plugin-instances")
|
||||
|
|
@ -296,7 +286,8 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
|
|||
// Then
|
||||
final Result actualResponseContent =
|
||||
JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
assertThat(actualResponseContent.toString()).isEqualTo(expectResponseContent.toString());
|
||||
assertThat(actualResponseContent.getMsg()).isEqualTo(expectResponseContent.getMsg());
|
||||
assertThat(actualResponseContent.getCode()).isEqualTo(expectResponseContent.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -323,6 +314,7 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
|
|||
// Then
|
||||
final Result actualResponseContent =
|
||||
JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
assertThat(actualResponseContent.toString()).isEqualTo(expectResponseContent.toString());
|
||||
assertThat(actualResponseContent.getMsg()).isEqualTo(expectResponseContent.getMsg());
|
||||
assertThat(actualResponseContent.getCode()).isEqualTo(expectResponseContent.getCode());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.api.controller;
|
|||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.dolphinscheduler.api.AssertionsHelper;
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.service.impl.DqExecuteResultServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.service.impl.DqRuleServiceImpl;
|
||||
|
|
@ -26,6 +27,7 @@ import org.apache.dolphinscheduler.api.utils.PageInfo;
|
|||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
import org.apache.dolphinscheduler.dao.entity.DqExecuteResult;
|
||||
import org.apache.dolphinscheduler.dao.entity.DqRule;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.plugin.task.api.enums.dp.RuleType;
|
||||
|
|
@ -33,7 +35,6 @@ import org.apache.dolphinscheduler.plugin.task.api.enums.dp.RuleType;
|
|||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -74,16 +75,10 @@ public class DataQualityControllerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetRuleFormCreateJsonById() throws Exception {
|
||||
public void testGetRuleFormCreateJsonById() {
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
putMsg(result, Status.SUCCESS);
|
||||
result.put(Constants.DATA_LIST, 1);
|
||||
|
||||
Mockito.when(dqRuleService.getRuleFormCreateJsonById(1)).thenReturn(result);
|
||||
|
||||
Result response = dataQualityController.getRuleFormCreateJsonById(1);
|
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
|
||||
Mockito.when(dqRuleService.getRuleFormCreateJsonById(1)).thenReturn("");
|
||||
AssertionsHelper.assertDoesNotThrow(() -> dataQualityController.getRuleFormCreateJsonById(1));
|
||||
}
|
||||
|
||||
private void putMsg(Map<String, Object> result, Status status, Object... statusParams) {
|
||||
|
|
@ -132,50 +127,38 @@ public class DataQualityControllerTest {
|
|||
pageInfo.setTotal(10);
|
||||
pageInfo.setTotalList(getRuleList());
|
||||
|
||||
Result result = new Result();
|
||||
result.setData(pageInfo);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
when(dqRuleService.queryRuleListPaging(user, searchVal, ruleType, start, end, 1, 10)).thenReturn(pageInfo);
|
||||
|
||||
when(dqRuleService.queryRuleListPaging(
|
||||
user, searchVal, ruleType, start, end, 1, 10)).thenReturn(result);
|
||||
|
||||
Result response = dataQualityController.queryRuleListPaging(user, searchVal, ruleType, start, end, 1, 10);
|
||||
Result<PageInfo<DqRule>> response =
|
||||
dataQualityController.queryRuleListPaging(user, searchVal, ruleType, start, end, 1, 10);
|
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryRuleList() throws Exception {
|
||||
public void testQueryRuleList() {
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
putMsg(result, Status.SUCCESS);
|
||||
result.put(Constants.DATA_LIST, getRuleList());
|
||||
when(dqRuleService.queryAllRuleList()).thenReturn(getRuleList());
|
||||
|
||||
when(dqRuleService.queryAllRuleList()).thenReturn(result);
|
||||
|
||||
Result response = dataQualityController.queryRuleList();
|
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
|
||||
Result<List<DqRule>> listResult = dataQualityController.queryRuleList();
|
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), listResult.getCode().intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryResultListPaging() throws Exception {
|
||||
public void testQueryResultListPaging() {
|
||||
|
||||
String searchVal = "";
|
||||
int ruleType = 0;
|
||||
String start = "2020-01-01 00:00:00";
|
||||
String end = "2020-01-02 00:00:00";
|
||||
|
||||
PageInfo<DqRule> pageInfo = new PageInfo<>(1, 10);
|
||||
PageInfo<DqExecuteResult> pageInfo = new PageInfo<>(1, 10);
|
||||
pageInfo.setTotal(10);
|
||||
|
||||
Result result = new Result();
|
||||
result.setData(pageInfo);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
when(dqExecuteResultService.queryResultListPaging(user, searchVal, 0, ruleType, start, end, 1, 10))
|
||||
.thenReturn(pageInfo);
|
||||
|
||||
when(dqExecuteResultService.queryResultListPaging(
|
||||
user, searchVal, 0, ruleType, start, end, 1, 10)).thenReturn(result);
|
||||
|
||||
Result response =
|
||||
Result<PageInfo<DqExecuteResult>> pageInfoResult =
|
||||
dataQualityController.queryExecuteResultListPaging(user, searchVal, ruleType, 0, start, end, 1, 10);
|
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
|
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), pageInfoResult.getCode().intValue());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,18 +17,19 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.controller;
|
||||
|
||||
import static org.apache.dolphinscheduler.api.AssertionsHelper.assertDoesNotThrow;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.service.impl.WorkFlowLineageServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
|
@ -73,23 +74,16 @@ public class WorkFlowLineageControllerTest {
|
|||
public void testQueryWorkFlowLineageByName() {
|
||||
long projectCode = 1L;
|
||||
String searchVal = "test";
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
putMsg(result, Status.SUCCESS);
|
||||
result.put(Constants.DATA_LIST, 1);
|
||||
Mockito.when(workFlowLineageService.queryWorkFlowLineageByName(projectCode, searchVal)).thenReturn(result);
|
||||
Result response = workFlowLineageController.queryWorkFlowLineageByName(user, projectCode, searchVal);
|
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
|
||||
Mockito.when(workFlowLineageService.queryWorkFlowLineageByName(projectCode, searchVal))
|
||||
.thenReturn(Collections.emptyList());
|
||||
assertDoesNotThrow(() -> workFlowLineageController.queryWorkFlowLineageByName(user, projectCode, searchVal));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryWorkFlowLineageByCode() {
|
||||
long projectCode = 1L;
|
||||
long code = 1L;
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
putMsg(result, Status.SUCCESS);
|
||||
result.put(Constants.DATA_LIST, 1);
|
||||
Mockito.when(workFlowLineageService.queryWorkFlowLineageByCode(projectCode, code)).thenReturn(result);
|
||||
Result response = workFlowLineageController.queryWorkFlowLineageByCode(user, projectCode, code);
|
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
|
||||
Mockito.when(workFlowLineageService.queryWorkFlowLineageByCode(projectCode, code)).thenReturn(new HashMap<>());
|
||||
assertDoesNotThrow(() -> workFlowLineageController.queryWorkFlowLineageByCode(user, projectCode, code));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,26 +17,30 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.controller.v2;
|
||||
|
||||
import static org.apache.dolphinscheduler.api.AssertionsHelper.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.dolphinscheduler.api.controller.AbstractControllerTest;
|
||||
import org.apache.dolphinscheduler.api.dto.DefineUserDto;
|
||||
import org.apache.dolphinscheduler.api.dto.TaskCountDto;
|
||||
import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.service.impl.DataAnalysisServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser;
|
||||
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
public class StatisticsV2ControllerTest extends AbstractControllerTest {
|
||||
|
||||
|
|
@ -54,113 +58,92 @@ public class StatisticsV2ControllerTest extends AbstractControllerTest {
|
|||
result.put("data", "AllWorkflowCounts = " + count);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
|
||||
Mockito.when(dataAnalysisService.queryAllWorkflowCounts(loginUser)).thenReturn(result);
|
||||
when(dataAnalysisService.queryAllWorkflowCounts(loginUser)).thenReturn(result);
|
||||
|
||||
Result result1 = statisticsV2Controller.queryWorkflowInstanceCounts(loginUser);
|
||||
|
||||
Assertions.assertTrue(result1.isSuccess());
|
||||
assertTrue(result1.isSuccess());
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testQueryWorkflowStatesCounts() {
|
||||
User loginUser = getLoginUser();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
StatisticsStateRequest statisticsStateRequest = new StatisticsStateRequest();
|
||||
List<ExecuteStatusCount> executeStatusCounts = new ArrayList<>();
|
||||
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
|
||||
result.put(Constants.DATA_LIST, taskCountResult);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
|
||||
Mockito.when(dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest)).thenReturn(result);
|
||||
when(dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest)).thenReturn(taskCountResult);
|
||||
|
||||
Result result1 = statisticsV2Controller.queryWorkflowStatesCounts(loginUser, statisticsStateRequest);
|
||||
|
||||
Assertions.assertTrue(result1.isSuccess());
|
||||
assertTrue(result1.isSuccess());
|
||||
}
|
||||
@Test
|
||||
public void testQueryOneWorkflowStates() {
|
||||
User loginUser = getLoginUser();
|
||||
Long workflowCode = 1L;
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
List<ExecuteStatusCount> executeStatusCounts = new ArrayList<>();
|
||||
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
|
||||
result.put(Constants.DATA_LIST, taskCountResult);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
|
||||
Mockito.when(dataAnalysisService.countOneWorkflowStates(loginUser, workflowCode)).thenReturn(result);
|
||||
when(dataAnalysisService.countOneWorkflowStates(loginUser, workflowCode)).thenReturn(taskCountResult);
|
||||
|
||||
Result result1 = statisticsV2Controller.queryOneWorkflowStates(loginUser, workflowCode);
|
||||
|
||||
Assertions.assertTrue(result1.isSuccess());
|
||||
assertTrue(result1.isSuccess());
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testQueryTaskStatesCounts() {
|
||||
User loginUser = getLoginUser();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
StatisticsStateRequest statisticsStateRequest = new StatisticsStateRequest();
|
||||
List<ExecuteStatusCount> executeStatusCounts = new ArrayList<>();
|
||||
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
|
||||
result.put(Constants.DATA_LIST, taskCountResult);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
|
||||
Mockito.when(dataAnalysisService.countTaskStates(loginUser, statisticsStateRequest)).thenReturn(result);
|
||||
when(dataAnalysisService.countTaskStates(loginUser, statisticsStateRequest)).thenReturn(taskCountResult);
|
||||
|
||||
Result result1 = statisticsV2Controller.queryTaskStatesCounts(loginUser, statisticsStateRequest);
|
||||
|
||||
Assertions.assertTrue(result1.isSuccess());
|
||||
assertTrue(result1.isSuccess());
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testQueryOneTaskStatesCounts() {
|
||||
User loginUser = getLoginUser();
|
||||
Long taskCode = 1L;
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
List<ExecuteStatusCount> executeStatusCounts = new ArrayList<>();
|
||||
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
|
||||
result.put(Constants.DATA_LIST, taskCountResult);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
|
||||
Mockito.when(dataAnalysisService.countOneTaskStates(loginUser, taskCode)).thenReturn(result);
|
||||
when(dataAnalysisService.countOneTaskStates(loginUser, taskCode)).thenReturn(taskCountResult);
|
||||
|
||||
Result result1 = statisticsV2Controller.queryOneTaskStatesCounts(loginUser, taskCode);
|
||||
|
||||
Assertions.assertTrue(result1.isSuccess());
|
||||
assertTrue(result1.isSuccess());
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testCountDefinitionByUser() {
|
||||
User loginUser = getLoginUser();
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
StatisticsStateRequest statisticsStateRequest = new StatisticsStateRequest();
|
||||
|
||||
List<ExecuteStatusCount> executeStatusCounts = new ArrayList<>();
|
||||
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
|
||||
result.put(Constants.DATA_LIST, taskCountResult);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
Mockito.when(dataAnalysisService.countDefinitionByUserV2(loginUser, statisticsStateRequest.getProjectCode(),
|
||||
null, null)).thenReturn(result);
|
||||
List<DefinitionGroupByUser> definitionGroupByUsers = new ArrayList<>();
|
||||
DefineUserDto taskCountResult = new DefineUserDto(definitionGroupByUsers);
|
||||
when(dataAnalysisService.countDefinitionByUserV2(loginUser, statisticsStateRequest.getProjectCode(), null,
|
||||
null)).thenReturn(taskCountResult);
|
||||
|
||||
Result result1 = statisticsV2Controller.countDefinitionByUser(loginUser, statisticsStateRequest);
|
||||
|
||||
Assertions.assertTrue(result1.isSuccess());
|
||||
assertDoesNotThrow(() -> statisticsV2Controller.countDefinitionByUser(loginUser, statisticsStateRequest));
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testCountDefinitionByUserId() {
|
||||
User loginUser = getLoginUser();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Integer userId = 1;
|
||||
|
||||
putMsg(result, Status.SUCCESS);
|
||||
DefineUserDto defineUserDto = new DefineUserDto(Collections.emptyList());
|
||||
when(dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, null)).thenReturn(defineUserDto);
|
||||
|
||||
Mockito.when(dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, null)).thenReturn(result);
|
||||
|
||||
Result result1 = statisticsV2Controller.countDefinitionByUserId(loginUser, userId);
|
||||
|
||||
Assertions.assertTrue(result1.isSuccess());
|
||||
assertDoesNotThrow(() -> statisticsV2Controller.countDefinitionByUserId(loginUser, userId));
|
||||
}
|
||||
|
||||
private User getLoginUser() {
|
||||
|
|
|
|||
|
|
@ -17,8 +17,13 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import static org.apache.dolphinscheduler.api.AssertionsHelper.assertDoesNotThrow;
|
||||
import static org.apache.dolphinscheduler.api.AssertionsHelper.assertThrowsServiceException;
|
||||
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.ACCESS_TOKEN_DELETE;
|
||||
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.ACCESS_TOKEN_UPDATE;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
|
@ -28,8 +33,6 @@ import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService
|
|||
import org.apache.dolphinscheduler.api.service.impl.AccessTokenServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
import org.apache.dolphinscheduler.common.utils.DateUtils;
|
||||
|
|
@ -41,10 +44,8 @@ import java.util.ArrayList;
|
|||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
|
|
@ -67,8 +68,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||
public class AccessTokenServiceTest {
|
||||
|
||||
private static final Logger baseServiceLogger = LoggerFactory.getLogger(BaseServiceImpl.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(AccessTokenServiceTest.class);
|
||||
|
||||
@InjectMocks
|
||||
private AccessTokenServiceImpl accessTokenService;
|
||||
|
||||
|
|
@ -87,16 +86,13 @@ public class AccessTokenServiceTest {
|
|||
user.setId(1);
|
||||
user.setUserType(UserType.ADMIN_USER);
|
||||
when(accessTokenMapper.selectAccessTokenPage(any(Page.class), eq("zhangsan"), eq(0))).thenReturn(tokenPage);
|
||||
Result result = accessTokenService.queryAccessTokenList(user, "zhangsan", 1, 10);
|
||||
PageInfo<AccessToken> pageInfo = (PageInfo<AccessToken>) result.getData();
|
||||
Assertions.assertEquals(0, (int) pageInfo.getTotal());
|
||||
PageInfo<AccessToken> pageInfo = accessTokenService.queryAccessTokenList(user, "zhangsan", 1, 10);
|
||||
assertEquals(0, (int) pageInfo.getTotal());
|
||||
|
||||
tokenPage.setTotal(1L);
|
||||
when(accessTokenMapper.selectAccessTokenPage(any(Page.class), eq("zhangsan"), eq(0))).thenReturn(tokenPage);
|
||||
result = accessTokenService.queryAccessTokenList(user, "zhangsan", 1, 10);
|
||||
pageInfo = (PageInfo<AccessToken>) result.getData();
|
||||
logger.info(result.toString());
|
||||
Assertions.assertTrue(pageInfo.getTotal() > 0);
|
||||
pageInfo = accessTokenService.queryAccessTokenList(user, "zhangsan", 1, 10);
|
||||
assertTrue(pageInfo.getTotal() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -104,24 +100,20 @@ public class AccessTokenServiceTest {
|
|||
User user = this.getLoginUser();
|
||||
user.setUserType(UserType.ADMIN_USER);
|
||||
List<AccessToken> accessTokenList = Lists.newArrayList(this.getEntity());
|
||||
Mockito.when(this.accessTokenMapper.queryAccessTokenByUser(Mockito.anyInt())).thenReturn(accessTokenList);
|
||||
Map<String, Object> result = this.accessTokenService.queryAccessTokenByUser(user, 1);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
when(this.accessTokenMapper.queryAccessTokenByUser(Mockito.anyInt())).thenReturn(accessTokenList);
|
||||
assertDoesNotThrow(() -> accessTokenService.queryAccessTokenByUser(user, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateToken() {
|
||||
// Given Token
|
||||
when(accessTokenMapper.insert(any(AccessToken.class))).thenReturn(2);
|
||||
Result result = accessTokenService.createToken(getLoginUser(), 1, getDate(), "AccessTokenServiceTest");
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
|
||||
assertDoesNotThrow(() -> {
|
||||
accessTokenService.createToken(getLoginUser(), 1, getDate(), "AccessTokenServiceTest");
|
||||
});
|
||||
|
||||
// Token is absent
|
||||
result = this.accessTokenService.createToken(getLoginUser(), 1, getDate(), null);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
|
||||
assertDoesNotThrow(() -> accessTokenService.createToken(getLoginUser(), 1, getDate(), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -129,11 +121,8 @@ public class AccessTokenServiceTest {
|
|||
User user = new User();
|
||||
user.setId(1);
|
||||
user.setUserType(UserType.ADMIN_USER);
|
||||
Map<String, Object> result = accessTokenService.generateToken(getLoginUser(), Integer.MAX_VALUE, getDate());
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
String token = (String) result.get(Constants.DATA_LIST);
|
||||
Assertions.assertNotNull(token);
|
||||
String token = accessTokenService.generateToken(getLoginUser(), Integer.MAX_VALUE, getDate());
|
||||
assertNotNull(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -143,27 +132,23 @@ public class AccessTokenServiceTest {
|
|||
User userLogin = new User();
|
||||
userLogin.setId(1);
|
||||
userLogin.setUserType(UserType.ADMIN_USER);
|
||||
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN, 1,
|
||||
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN, 1,
|
||||
ACCESS_TOKEN_DELETE, baseServiceLogger)).thenReturn(true);
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0,
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0,
|
||||
baseServiceLogger)).thenReturn(true);
|
||||
// not exist
|
||||
Map<String, Object> result = accessTokenService.delAccessTokenById(userLogin, 0);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.ACCESS_TOKEN_NOT_EXIST, result.get(Constants.STATUS));
|
||||
assertThrowsServiceException(Status.ACCESS_TOKEN_NOT_EXIST,
|
||||
() -> accessTokenService.deleteAccessTokenById(userLogin, 0));
|
||||
// no operate
|
||||
userLogin.setId(2);
|
||||
result = accessTokenService.delAccessTokenById(userLogin, 1);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS));
|
||||
assertThrowsServiceException(Status.USER_NO_OPERATION_PERM,
|
||||
() -> accessTokenService.deleteAccessTokenById(userLogin, 1));
|
||||
// success
|
||||
userLogin.setId(1);
|
||||
userLogin.setUserType(UserType.ADMIN_USER);
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0,
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0,
|
||||
baseServiceLogger)).thenReturn(true);
|
||||
result = accessTokenService.delAccessTokenById(userLogin, 1);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
assertDoesNotThrow(() -> accessTokenService.deleteAccessTokenById(userLogin, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -171,30 +156,26 @@ public class AccessTokenServiceTest {
|
|||
User user = new User();
|
||||
user.setId(1);
|
||||
user.setUserType(UserType.ADMIN_USER);
|
||||
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN, 1,
|
||||
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN, 1,
|
||||
ACCESS_TOKEN_UPDATE, baseServiceLogger)).thenReturn(true);
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0,
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0,
|
||||
baseServiceLogger)).thenReturn(true);
|
||||
// Given Token
|
||||
when(accessTokenMapper.selectById(1)).thenReturn(getEntity());
|
||||
Map<String, Object> result =
|
||||
when(accessTokenMapper.updateById(any())).thenReturn(1);
|
||||
AccessToken accessToken =
|
||||
accessTokenService.updateToken(getLoginUser(), 1, Integer.MAX_VALUE, getDate(), "token");
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
Assertions.assertNotNull(result.get(Constants.DATA_LIST));
|
||||
assertEquals("token", accessToken.getToken());
|
||||
|
||||
// Token is absent
|
||||
result = accessTokenService.updateToken(getLoginUser(), 1, Integer.MAX_VALUE, getDate(), null);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
Assertions.assertNotNull(result.get(Constants.DATA_LIST));
|
||||
accessToken = accessTokenService.updateToken(getLoginUser(), 1, Integer.MAX_VALUE, getDate(), null);
|
||||
assertNotNull(accessToken.getToken());
|
||||
|
||||
// ACCESS_TOKEN_NOT_EXIST
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0,
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0,
|
||||
baseServiceLogger)).thenReturn(true);
|
||||
result = accessTokenService.updateToken(getLoginUser(), 2, Integer.MAX_VALUE, getDate(), "token");
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.ACCESS_TOKEN_NOT_EXIST, result.get(Constants.STATUS));
|
||||
assertThrowsServiceException(Status.ACCESS_TOKEN_NOT_EXIST,
|
||||
() -> accessTokenService.updateToken(getLoginUser(), 2, Integer.MAX_VALUE, getDate(), "token"));
|
||||
}
|
||||
|
||||
private User getLoginUser() {
|
||||
|
|
|
|||
|
|
@ -17,19 +17,21 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import static org.apache.dolphinscheduler.api.AssertionsHelper.assertDoesNotThrow;
|
||||
import static org.apache.dolphinscheduler.api.AssertionsHelper.assertThrowsServiceException;
|
||||
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.ALERT_GROUP_CREATE;
|
||||
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.ALERT_GROUP_DELETE;
|
||||
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.ALERT_GROUP_UPDATE;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService;
|
||||
import org.apache.dolphinscheduler.api.service.impl.AlertGroupServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
import org.apache.dolphinscheduler.dao.entity.AlertGroup;
|
||||
|
|
@ -40,7 +42,6 @@ import org.apache.commons.collections4.CollectionUtils;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
@ -81,21 +82,17 @@ public class AlertGroupServiceTest {
|
|||
@Test
|
||||
public void testQueryAlertGroup() {
|
||||
|
||||
Mockito.when(alertGroupMapper.queryAllGroupList()).thenReturn(getList());
|
||||
Map<String, Object> result = alertGroupService.queryAlertgroup(getLoginUser());
|
||||
logger.info(result.toString());
|
||||
List<AlertGroup> alertGroups = (List<AlertGroup>) result.get(Constants.DATA_LIST);
|
||||
Assertions.assertEquals(alertGroups.size(), 2);
|
||||
when(alertGroupMapper.queryAllGroupList()).thenReturn(getList());
|
||||
List<AlertGroup> alertGroups = alertGroupService.queryAllAlertGroup(getLoginUser());
|
||||
Assertions.assertEquals(2, alertGroups.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryNormalAlertGroup() {
|
||||
|
||||
Mockito.when(alertGroupMapper.queryAllGroupList()).thenReturn(getList());
|
||||
Map<String, Object> result = alertGroupService.queryNormalAlertgroup(getLoginUser());
|
||||
logger.info(result.toString());
|
||||
List<AlertGroup> alertGroups = (List<AlertGroup>) result.get(Constants.DATA_LIST);
|
||||
Assertions.assertEquals(alertGroups.size(), 1);
|
||||
when(alertGroupMapper.queryAllGroupList()).thenReturn(getList());
|
||||
List<AlertGroup> alertGroups = alertGroupService.queryNormalAlertGroups(getLoginUser());
|
||||
Assertions.assertEquals(1, alertGroups.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -103,64 +100,57 @@ public class AlertGroupServiceTest {
|
|||
IPage<AlertGroup> page = new Page<>(1, 10);
|
||||
page.setTotal(2L);
|
||||
page.setRecords(getList());
|
||||
Mockito.when(alertGroupMapper.queryAlertGroupPage(any(Page.class), eq(groupName))).thenReturn(page);
|
||||
when(alertGroupMapper.queryAlertGroupPage(any(Page.class), eq(groupName))).thenReturn(page);
|
||||
User user = new User();
|
||||
// no operate
|
||||
user.setUserType(UserType.GENERAL_USER);
|
||||
user.setId(88);
|
||||
|
||||
Result result = alertGroupService.listPaging(user, groupName, 1, 10);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode());
|
||||
PageInfo<AlertGroup> alertGroupPageInfo = alertGroupService.listPaging(user, groupName, 1, 10);
|
||||
assertNotNull(alertGroupPageInfo);
|
||||
// success
|
||||
user.setUserType(UserType.ADMIN_USER);
|
||||
user.setId(0);
|
||||
result = alertGroupService.listPaging(user, groupName, 1, 10);
|
||||
logger.info(result.toString());
|
||||
PageInfo<AlertGroup> pageInfo = (PageInfo<AlertGroup>) result.getData();
|
||||
Assertions.assertTrue(CollectionUtils.isNotEmpty(pageInfo.getTotalList()));
|
||||
alertGroupPageInfo = alertGroupService.listPaging(user, groupName, 1, 10);
|
||||
Assertions.assertTrue(CollectionUtils.isNotEmpty(alertGroupPageInfo.getTotalList()));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAlertgroup() {
|
||||
|
||||
Mockito.when(alertGroupMapper.insert(any(AlertGroup.class))).thenReturn(3);
|
||||
when(alertGroupMapper.insert(any(AlertGroup.class))).thenReturn(3);
|
||||
User user = new User();
|
||||
user.setId(0);
|
||||
// no operate
|
||||
user.setUserType(UserType.GENERAL_USER);
|
||||
Map<String, Object> result = alertGroupService.createAlertgroup(user, groupName, groupName, null);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS));
|
||||
assertThrowsServiceException(Status.USER_NO_OPERATION_PERM,
|
||||
() -> alertGroupService.createAlertGroup(user, groupName, groupName, null));
|
||||
|
||||
user.setUserType(UserType.ADMIN_USER);
|
||||
user.setId(0);
|
||||
// success
|
||||
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
user.getId(), ALERT_GROUP_CREATE, baseServiceLogger)).thenReturn(true);
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, null,
|
||||
user.getId(), baseServiceLogger)).thenReturn(true);
|
||||
result = alertGroupService.createAlertgroup(user, groupName, groupName, null);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
Assertions.assertNotNull(result.get(Constants.DATA_LIST));
|
||||
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP, user.getId(),
|
||||
ALERT_GROUP_CREATE, baseServiceLogger)).thenReturn(true);
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, null, user.getId(),
|
||||
baseServiceLogger)).thenReturn(true);
|
||||
AlertGroup alertGroup = alertGroupService.createAlertGroup(user, groupName, groupName, null);
|
||||
assertNotNull(alertGroup);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAlertgroupDuplicate() {
|
||||
|
||||
Mockito.when(alertGroupMapper.insert(any(AlertGroup.class)))
|
||||
.thenThrow(new DuplicateKeyException("group name exist"));
|
||||
when(alertGroupMapper.insert(any(AlertGroup.class))).thenThrow(new DuplicateKeyException("group name exist"));
|
||||
User user = new User();
|
||||
user.setUserType(UserType.ADMIN_USER);
|
||||
user.setId(0);
|
||||
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
user.getId(), ALERT_GROUP_CREATE, baseServiceLogger)).thenReturn(true);
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, null,
|
||||
user.getId(), baseServiceLogger)).thenReturn(true);
|
||||
Map<String, Object> result = alertGroupService.createAlertgroup(user, groupName, groupName, null);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.ALERT_GROUP_EXIST, result.get(Constants.STATUS));
|
||||
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP, user.getId(),
|
||||
ALERT_GROUP_CREATE, baseServiceLogger)).thenReturn(true);
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, null, user.getId(),
|
||||
baseServiceLogger)).thenReturn(true);
|
||||
assertThrowsServiceException(Status.ALERT_GROUP_EXIST,
|
||||
() -> alertGroupService.createAlertGroup(user, groupName, groupName, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -170,27 +160,22 @@ public class AlertGroupServiceTest {
|
|||
user.setId(0);
|
||||
// no operate
|
||||
user.setUserType(UserType.GENERAL_USER);
|
||||
Map<String, Object> result = alertGroupService.updateAlertgroup(user, 1, groupName, groupName, null);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS));
|
||||
assertThrowsServiceException(Status.USER_NO_OPERATION_PERM,
|
||||
() -> alertGroupService.updateAlertGroupById(user, 1, groupName, groupName, null));
|
||||
user.setUserType(UserType.ADMIN_USER);
|
||||
// not exist
|
||||
user.setUserType(UserType.ADMIN_USER);
|
||||
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
user.getId(), ALERT_GROUP_UPDATE, baseServiceLogger)).thenReturn(true);
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
new Object[]{1}, 0, baseServiceLogger)).thenReturn(true);
|
||||
result = alertGroupService.updateAlertgroup(user, 1, groupName, groupName, null);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.ALERT_GROUP_NOT_EXIST, result.get(Constants.STATUS));
|
||||
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP, user.getId(),
|
||||
ALERT_GROUP_UPDATE, baseServiceLogger)).thenReturn(true);
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, new Object[]{1}, 0,
|
||||
baseServiceLogger)).thenReturn(true);
|
||||
assertThrowsServiceException(Status.ALERT_GROUP_NOT_EXIST,
|
||||
() -> alertGroupService.updateAlertGroupById(user, 1, groupName, groupName, null));
|
||||
// success
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
new Object[]{3}, user.getId(), baseServiceLogger)).thenReturn(true);
|
||||
Mockito.when(alertGroupMapper.selectById(3)).thenReturn(getEntity());
|
||||
result = alertGroupService.updateAlertgroup(user, 3, groupName, groupName, null);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, new Object[]{3},
|
||||
user.getId(), baseServiceLogger)).thenReturn(true);
|
||||
when(alertGroupMapper.selectById(3)).thenReturn(getEntity());
|
||||
assertDoesNotThrow(() -> alertGroupService.updateAlertGroupById(user, 3, groupName, groupName, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -198,15 +183,15 @@ public class AlertGroupServiceTest {
|
|||
User user = new User();
|
||||
user.setId(0);
|
||||
user.setUserType(UserType.ADMIN_USER);
|
||||
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
user.getId(), ALERT_GROUP_UPDATE, baseServiceLogger)).thenReturn(true);
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
new Object[]{3}, user.getId(), baseServiceLogger)).thenReturn(true);
|
||||
Mockito.when(alertGroupMapper.selectById(3)).thenReturn(getEntity());
|
||||
Mockito.when(alertGroupMapper.updateById(Mockito.any()))
|
||||
when(alertGroupMapper.selectById(3)).thenReturn(getEntity());
|
||||
when(alertGroupMapper.updateById(Mockito.any()))
|
||||
.thenThrow(new DuplicateKeyException("group name exist"));
|
||||
Map<String, Object> result = alertGroupService.updateAlertgroup(user, 3, groupName, groupName, null);
|
||||
Assertions.assertEquals(Status.ALERT_GROUP_EXIST, result.get(Constants.STATUS));
|
||||
assertThrowsServiceException(Status.ALERT_GROUP_EXIST,
|
||||
() -> alertGroupService.updateAlertGroupById(user, 3, groupName, groupName, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -217,8 +202,8 @@ public class AlertGroupServiceTest {
|
|||
AlertGroup globalAlertGroup = new AlertGroup();
|
||||
globalAlertGroup.setId(2);
|
||||
globalAlertGroup.setGroupName("global alert group");
|
||||
Map<String, Object> result = alertGroupService.updateAlertgroup(user, 2, groupName, groupName, null);
|
||||
Assertions.assertEquals(Status.NOT_ALLOW_TO_UPDATE_GLOBAL_ALARM_GROUP, result.get(Constants.STATUS));
|
||||
assertThrowsServiceException(Status.NOT_ALLOW_TO_UPDATE_GLOBAL_ALARM_GROUP,
|
||||
() -> alertGroupService.updateAlertGroupById(user, 2, groupName, groupName, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -227,42 +212,36 @@ public class AlertGroupServiceTest {
|
|||
user.setId(0);
|
||||
// no operate
|
||||
user.setUserType(UserType.GENERAL_USER);
|
||||
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
user.getId(), ALERT_GROUP_DELETE, baseServiceLogger)).thenReturn(true);
|
||||
Map<String, Object> result = alertGroupService.delAlertgroupById(user, 1);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS));
|
||||
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP, user.getId(),
|
||||
ALERT_GROUP_DELETE, baseServiceLogger)).thenReturn(true);
|
||||
assertThrowsServiceException(Status.USER_NO_OPERATION_PERM,
|
||||
() -> alertGroupService.deleteAlertGroupById(user, 1));
|
||||
|
||||
// not exist
|
||||
user.setUserType(UserType.ADMIN_USER);
|
||||
user.setId(0);
|
||||
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
user.getId(), ALERT_GROUP_DELETE, baseServiceLogger)).thenReturn(true);
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
new Object[]{3}, 0, baseServiceLogger)).thenReturn(true);
|
||||
result = alertGroupService.delAlertgroupById(user, 3);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.ALERT_GROUP_NOT_EXIST, result.get(Constants.STATUS));
|
||||
assertThrowsServiceException(Status.ALERT_GROUP_NOT_EXIST,
|
||||
() -> alertGroupService.deleteAlertGroupById(user, 3));
|
||||
|
||||
// not allowed1
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
new Object[]{1}, 0, baseServiceLogger)).thenReturn(true);
|
||||
result = alertGroupService.delAlertgroupById(user, 1);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.NOT_ALLOW_TO_DELETE_DEFAULT_ALARM_GROUP, result.get(Constants.STATUS));
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, new Object[]{1}, 0,
|
||||
baseServiceLogger)).thenReturn(true);
|
||||
assertThrowsServiceException(Status.NOT_ALLOW_TO_DELETE_DEFAULT_ALARM_GROUP,
|
||||
() -> alertGroupService.deleteAlertGroupById(user, 1));
|
||||
// not allowed2
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
new Object[]{2}, 0, baseServiceLogger)).thenReturn(true);
|
||||
result = alertGroupService.delAlertgroupById(user, 2);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.NOT_ALLOW_TO_DELETE_DEFAULT_ALARM_GROUP, result.get(Constants.STATUS));
|
||||
assertThrowsServiceException(Status.NOT_ALLOW_TO_DELETE_DEFAULT_ALARM_GROUP,
|
||||
() -> alertGroupService.deleteAlertGroupById(user, 2));
|
||||
// success
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP,
|
||||
new Object[]{4}, 0, baseServiceLogger)).thenReturn(true);
|
||||
Mockito.when(alertGroupMapper.selectById(4)).thenReturn(getEntity());
|
||||
result = alertGroupService.delAlertgroupById(user, 4);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, new Object[]{4}, 0,
|
||||
baseServiceLogger)).thenReturn(true);
|
||||
when(alertGroupMapper.selectById(4)).thenReturn(getEntity());
|
||||
assertDoesNotThrow(() -> alertGroupService.deleteAlertGroupById(user, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -270,7 +249,7 @@ public class AlertGroupServiceTest {
|
|||
// group name not exist
|
||||
boolean result = alertGroupService.existGroupName(groupName);
|
||||
Assertions.assertFalse(result);
|
||||
Mockito.when(alertGroupMapper.existGroupName(groupName)).thenReturn(true);
|
||||
when(alertGroupMapper.existGroupName(groupName)).thenReturn(true);
|
||||
|
||||
// group name exist
|
||||
result = alertGroupService.existGroupName(groupName);
|
||||
|
|
|
|||
|
|
@ -17,16 +17,17 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import static org.apache.dolphinscheduler.api.AssertionsHelper.assertThrowsServiceException;
|
||||
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.ALART_INSTANCE_CREATE;
|
||||
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.ALERT_PLUGIN_DELETE;
|
||||
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.ALERT_PLUGIN_UPDATE;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService;
|
||||
import org.apache.dolphinscheduler.api.service.impl.AlertPluginInstanceServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.AlertPluginInstanceType;
|
||||
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
|
|
@ -40,7 +41,6 @@ import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper;
|
|||
import org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper;
|
||||
import org.apache.dolphinscheduler.dao.mapper.PluginDefineMapper;
|
||||
import org.apache.dolphinscheduler.extract.alert.request.AlertSendResponse;
|
||||
import org.apache.dolphinscheduler.extract.alert.request.AlertTestSendRequest;
|
||||
import org.apache.dolphinscheduler.registry.api.RegistryClient;
|
||||
import org.apache.dolphinscheduler.registry.api.enums.RegistryNodeType;
|
||||
|
||||
|
|
@ -48,7 +48,6 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
|
@ -185,83 +184,79 @@ public class AlertPluginInstanceServiceTest {
|
|||
|
||||
@Test
|
||||
public void testCreate() {
|
||||
Mockito.when(alertPluginInstanceMapper.existInstanceName("test")).thenReturn(true);
|
||||
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
|
||||
when(alertPluginInstanceMapper.existInstanceName("test")).thenReturn(true);
|
||||
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
|
||||
1, ALART_INSTANCE_CREATE, baseServiceLogger)).thenReturn(true);
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
|
||||
null, 0, baseServiceLogger)).thenReturn(true);
|
||||
Map<String, Object> result =
|
||||
alertPluginInstanceService.create(user, 1, "test", normalInstanceType, warningType, uiParams);
|
||||
Assertions.assertEquals(Status.PLUGIN_INSTANCE_ALREADY_EXISTS, result.get(Constants.STATUS));
|
||||
Mockito.when(alertPluginInstanceMapper.insert(Mockito.any())).thenReturn(1);
|
||||
result = alertPluginInstanceService.create(user, 1, "test1", normalInstanceType, warningType, uiParams);
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
Assertions.assertNotNull(result.get(Constants.DATA_LIST));
|
||||
assertThrowsServiceException(Status.PLUGIN_INSTANCE_ALREADY_EXISTS,
|
||||
() -> alertPluginInstanceService.create(user, 1, "test", normalInstanceType, warningType, uiParams));
|
||||
when(alertPluginInstanceMapper.insert(Mockito.any())).thenReturn(1);
|
||||
AlertPluginInstance alertPluginInstance =
|
||||
alertPluginInstanceService.create(user, 1, "test1", normalInstanceType, warningType, uiParams);
|
||||
assertNotNull(alertPluginInstance);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendAlert() {
|
||||
Result<Void> result;
|
||||
Mockito.when(registryClient.getServerList(RegistryNodeType.ALERT_SERVER)).thenReturn(new ArrayList<>());
|
||||
result = alertPluginInstanceService.testSend(1, uiParams);
|
||||
Assertions.assertEquals(Status.ALERT_SERVER_NOT_EXIST.getCode(), result.getCode());
|
||||
assertThrowsServiceException(Status.ALERT_SERVER_NOT_EXIST,
|
||||
() -> alertPluginInstanceService.testSend(1, uiParams));
|
||||
AlertSendResponse.AlertSendResponseResult alertResult = new AlertSendResponse.AlertSendResponseResult();
|
||||
alertResult.setSuccess(true);
|
||||
AlertTestSendRequest alertTestSendRequest = new AlertTestSendRequest(
|
||||
1,
|
||||
uiParams);
|
||||
Server server = new Server();
|
||||
server.setPort(50052);
|
||||
server.setHost("127.0.0.1");
|
||||
Mockito.when(registryClient.getServerList(RegistryNodeType.ALERT_SERVER))
|
||||
.thenReturn(Collections.singletonList(server));
|
||||
result = alertPluginInstanceService.testSend(1, uiParams);
|
||||
Assertions.assertEquals(Status.ALERT_TEST_SENDING_FAILED.getCode(), result.getCode());
|
||||
assertThrowsServiceException(Status.ALERT_TEST_SENDING_FAILED,
|
||||
() -> alertPluginInstanceService.testSend(1, uiParams));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelete() {
|
||||
List<String> ids = Arrays.asList("11,2,3", "5,96", null, "98,1");
|
||||
Mockito.when(alertGroupMapper.queryInstanceIdsList()).thenReturn(ids);
|
||||
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
|
||||
when(alertGroupMapper.queryInstanceIdsList()).thenReturn(ids);
|
||||
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
|
||||
1, ALERT_PLUGIN_DELETE, baseServiceLogger)).thenReturn(true);
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
|
||||
null, 0, baseServiceLogger)).thenReturn(true);
|
||||
AlertPluginInstance normalInstanceWithId1 = getAlertPluginInstance(1, normalInstanceType, "test1");
|
||||
AlertPluginInstance normalInstanceWithId9 = getAlertPluginInstance(9, normalInstanceType, "test9");
|
||||
AlertPluginInstance globalInstanceWithId5 = getAlertPluginInstance(5, globalInstanceType, "test5");
|
||||
Mockito.when(alertPluginInstanceMapper.selectById(1)).thenReturn(normalInstanceWithId1);
|
||||
Mockito.when(alertPluginInstanceMapper.selectById(9)).thenReturn(normalInstanceWithId9);
|
||||
Mockito.when(alertPluginInstanceMapper.selectById(5)).thenReturn(globalInstanceWithId5);
|
||||
when(alertPluginInstanceMapper.selectById(1)).thenReturn(normalInstanceWithId1);
|
||||
when(alertPluginInstanceMapper.selectById(9)).thenReturn(normalInstanceWithId9);
|
||||
when(alertPluginInstanceMapper.selectById(5)).thenReturn(globalInstanceWithId5);
|
||||
AlertGroup globalAlertGroup = new AlertGroup();
|
||||
globalAlertGroup.setId(2);
|
||||
globalAlertGroup.setAlertInstanceIds("5,96");
|
||||
Mockito.when(alertGroupMapper.selectById(2)).thenReturn(globalAlertGroup);
|
||||
Mockito.when(alertGroupMapper.updateById(Mockito.any())).thenReturn(1);
|
||||
Map<String, Object> result;
|
||||
result = alertPluginInstanceService.delete(user, 1);
|
||||
Assertions.assertEquals(Status.DELETE_ALERT_PLUGIN_INSTANCE_ERROR_HAS_ALERT_GROUP_ASSOCIATED,
|
||||
result.get(Constants.STATUS));
|
||||
Mockito.when(alertPluginInstanceMapper.deleteById(9)).thenReturn(1);
|
||||
result = alertPluginInstanceService.delete(user, 9);
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
Mockito.when(alertPluginInstanceMapper.deleteById(5)).thenReturn(1);
|
||||
result = alertPluginInstanceService.delete(user, 5);
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
when(alertGroupMapper.selectById(2)).thenReturn(globalAlertGroup);
|
||||
when(alertGroupMapper.updateById(Mockito.any())).thenReturn(1);
|
||||
|
||||
assertThrowsServiceException(Status.DELETE_ALERT_PLUGIN_INSTANCE_ERROR_HAS_ALERT_GROUP_ASSOCIATED,
|
||||
() -> alertPluginInstanceService.deleteById(user, 1));
|
||||
|
||||
when(alertPluginInstanceMapper.deleteById(9)).thenReturn(1);
|
||||
Assertions.assertDoesNotThrow(() -> alertPluginInstanceService.deleteById(user, 9));
|
||||
|
||||
when(alertPluginInstanceMapper.deleteById(5)).thenReturn(1);
|
||||
Assertions.assertDoesNotThrow(() -> alertPluginInstanceService.deleteById(user, 5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate() {
|
||||
Mockito.when(alertPluginInstanceMapper.updateById(Mockito.any())).thenReturn(0);
|
||||
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
|
||||
1, ALERT_PLUGIN_UPDATE, baseServiceLogger)).thenReturn(true);
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
|
||||
null, 0, baseServiceLogger)).thenReturn(true);
|
||||
Map<String, Object> result = alertPluginInstanceService.update(user, 1, "testUpdate", warningType, uiParams);
|
||||
Assertions.assertEquals(Status.SAVE_ERROR, result.get(Constants.STATUS));
|
||||
Mockito.when(alertPluginInstanceMapper.updateById(Mockito.any())).thenReturn(1);
|
||||
result = alertPluginInstanceService.update(user, 1, "testUpdate", warningType, uiParams);
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
when(alertPluginInstanceMapper.updateById(Mockito.any())).thenReturn(0);
|
||||
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE, 1,
|
||||
ALERT_PLUGIN_UPDATE, baseServiceLogger)).thenReturn(true);
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE, null, 0,
|
||||
baseServiceLogger)).thenReturn(true);
|
||||
assertThrowsServiceException(Status.SAVE_ERROR,
|
||||
() -> alertPluginInstanceService.updateById(user, 1, "testUpdate", warningType, uiParams));
|
||||
|
||||
when(alertPluginInstanceMapper.updateById(Mockito.any())).thenReturn(1);
|
||||
AlertPluginInstance alertPluginInstance =
|
||||
alertPluginInstanceService.updateById(user, 1, "testUpdate", warningType, uiParams);
|
||||
Assertions.assertNotNull(alertPluginInstance);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -271,10 +266,9 @@ public class AlertPluginInstanceServiceTest {
|
|||
pluginDefine.setId(1);
|
||||
List<PluginDefine> pluginDefines = Collections.singletonList(pluginDefine);
|
||||
List<AlertPluginInstance> pluginInstanceList = Collections.singletonList(alertPluginInstance);
|
||||
Mockito.when(alertPluginInstanceMapper.queryAllAlertPluginInstanceList()).thenReturn(pluginInstanceList);
|
||||
Mockito.when(pluginDefineMapper.queryAllPluginDefineList()).thenReturn(pluginDefines);
|
||||
Map<String, Object> result = alertPluginInstanceService.queryAll();
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
when(alertPluginInstanceMapper.queryAllAlertPluginInstanceList()).thenReturn(pluginInstanceList);
|
||||
when(pluginDefineMapper.queryAllPluginDefineList()).thenReturn(pluginDefines);
|
||||
Assertions.assertDoesNotThrow(() -> alertPluginInstanceService.queryAll());
|
||||
}
|
||||
|
||||
private AlertPluginInstance getAlertPluginInstance(int id, AlertPluginInstanceType instanceType,
|
||||
|
|
|
|||
|
|
@ -20,9 +20,7 @@ package org.apache.dolphinscheduler.api.service;
|
|||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.service.impl.AuditServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.utils.DateUtils;
|
||||
import org.apache.dolphinscheduler.dao.entity.AuditLog;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
|
@ -67,13 +65,19 @@ public class AuditServiceTest {
|
|||
IPage<AuditLog> page = new Page<>(1, 10);
|
||||
page.setRecords(getLists());
|
||||
page.setTotal(1L);
|
||||
when(auditLogMapper.queryAuditLog(Mockito.any(Page.class), Mockito.any(), Mockito.any(),
|
||||
Mockito.eq(""), eq(start), eq(end)))
|
||||
.thenReturn(page);
|
||||
Result result = auditService.queryLogListPaging(new User(), null, null, "2020-11-01 00:00:00",
|
||||
"2020-11-02 00:00:00", "", 1, 10);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode());
|
||||
when(auditLogMapper.queryAuditLog(Mockito.any(Page.class), Mockito.any(), Mockito.any(), Mockito.eq(""),
|
||||
eq(start), eq(end))).thenReturn(page);
|
||||
Assertions.assertDoesNotThrow(() -> {
|
||||
auditService.queryLogListPaging(
|
||||
new User(),
|
||||
null,
|
||||
null,
|
||||
"2020-11-01 00:00:00",
|
||||
"2020-11-02 00:00:00",
|
||||
"",
|
||||
1,
|
||||
10);
|
||||
});
|
||||
}
|
||||
|
||||
private List<AuditLog> getLists() {
|
||||
|
|
|
|||
|
|
@ -1,292 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.k8s.K8sManager;
|
||||
import org.apache.dolphinscheduler.api.service.impl.ClusterServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
import org.apache.dolphinscheduler.dao.entity.Cluster;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.dao.mapper.ClusterMapper;
|
||||
import org.apache.dolphinscheduler.dao.mapper.K8sNamespaceMapper;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
/**
|
||||
* cluster service test
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class ClusterServiceTest {
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(ClusterServiceTest.class);
|
||||
|
||||
@InjectMocks
|
||||
private ClusterServiceImpl clusterService;
|
||||
|
||||
@Mock
|
||||
private ClusterMapper clusterMapper;
|
||||
|
||||
@Mock
|
||||
private K8sNamespaceMapper k8sNamespaceMapper;
|
||||
|
||||
@Mock
|
||||
private K8sManager k8sManager;
|
||||
|
||||
public static final String testUserName = "clusterServerTest";
|
||||
|
||||
public static final String clusterName = "Env1";
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void after() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateCluster() {
|
||||
User loginUser = getGeneralUser();
|
||||
Map<String, Object> result = clusterService.createCluster(loginUser, clusterName, getConfig(), getDesc());
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS));
|
||||
|
||||
loginUser = getAdminUser();
|
||||
result = clusterService.createCluster(loginUser, clusterName, "", getDesc());
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.CLUSTER_CONFIG_IS_NULL, result.get(Constants.STATUS));
|
||||
|
||||
result = clusterService.createCluster(loginUser, "", getConfig(), getDesc());
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.CLUSTER_NAME_IS_NULL, result.get(Constants.STATUS));
|
||||
|
||||
Mockito.when(clusterMapper.queryByClusterName(clusterName)).thenReturn(getCluster());
|
||||
result = clusterService.createCluster(loginUser, clusterName, getConfig(), getDesc());
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.CLUSTER_NAME_EXISTS, result.get(Constants.STATUS));
|
||||
|
||||
Mockito.when(clusterMapper.insert(Mockito.any(Cluster.class))).thenReturn(1);
|
||||
result = clusterService.createCluster(loginUser, "testName", "testConfig", "testDesc");
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckParams() {
|
||||
Map<String, Object> result = clusterService.checkParams(clusterName, getConfig());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
result = clusterService.checkParams("", getConfig());
|
||||
Assertions.assertEquals(Status.CLUSTER_NAME_IS_NULL, result.get(Constants.STATUS));
|
||||
result = clusterService.checkParams(clusterName, "");
|
||||
Assertions.assertEquals(Status.CLUSTER_CONFIG_IS_NULL, result.get(Constants.STATUS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateClusterByCode() {
|
||||
User loginUser = getGeneralUser();
|
||||
Map<String, Object> result =
|
||||
clusterService.updateClusterByCode(loginUser, 1L, clusterName, getConfig(), getDesc());
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS));
|
||||
|
||||
loginUser = getAdminUser();
|
||||
result = clusterService.updateClusterByCode(loginUser, 1L, clusterName, "", getDesc());
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.CLUSTER_CONFIG_IS_NULL, result.get(Constants.STATUS));
|
||||
|
||||
result = clusterService.updateClusterByCode(loginUser, 1L, "", getConfig(), getDesc());
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.CLUSTER_NAME_IS_NULL, result.get(Constants.STATUS));
|
||||
|
||||
result = clusterService.updateClusterByCode(loginUser, 2L, clusterName, getConfig(), getDesc());
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.CLUSTER_NOT_EXISTS, result.get(Constants.STATUS));
|
||||
|
||||
Mockito.when(clusterMapper.queryByClusterName(clusterName)).thenReturn(getCluster());
|
||||
result = clusterService.updateClusterByCode(loginUser, 2L, clusterName, getConfig(), getDesc());
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.CLUSTER_NAME_EXISTS, result.get(Constants.STATUS));
|
||||
|
||||
Mockito.when(clusterMapper.updateById(Mockito.any(Cluster.class))).thenReturn(1);
|
||||
Mockito.when(clusterMapper.queryByClusterCode(1L)).thenReturn(getCluster());
|
||||
|
||||
result = clusterService.updateClusterByCode(loginUser, 1L, "testName", getConfig(), "test");
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryAllClusterList() {
|
||||
Mockito.when(clusterMapper.queryAllClusterList()).thenReturn(Lists.newArrayList(getCluster()));
|
||||
Map<String, Object> result = clusterService.queryAllClusterList();
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
|
||||
List<Cluster> list = (List<Cluster>) (result.get(Constants.DATA_LIST));
|
||||
Assertions.assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryClusterListPaging() {
|
||||
IPage<Cluster> page = new Page<>(1, 10);
|
||||
page.setRecords(getList());
|
||||
page.setTotal(1L);
|
||||
Mockito.when(clusterMapper.queryClusterListPaging(Mockito.any(Page.class), Mockito.eq(clusterName)))
|
||||
.thenReturn(page);
|
||||
|
||||
Result result = clusterService.queryClusterListPaging(1, 10, clusterName);
|
||||
logger.info(result.toString());
|
||||
PageInfo<Cluster> pageInfo = (PageInfo<Cluster>) result.getData();
|
||||
Assertions.assertTrue(CollectionUtils.isNotEmpty(pageInfo.getTotalList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryClusterByName() {
|
||||
Mockito.when(clusterMapper.queryByClusterName(clusterName)).thenReturn(null);
|
||||
Map<String, Object> result = clusterService.queryClusterByName(clusterName);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.QUERY_CLUSTER_BY_NAME_ERROR, result.get(Constants.STATUS));
|
||||
|
||||
Mockito.when(clusterMapper.queryByClusterName(clusterName)).thenReturn(getCluster());
|
||||
result = clusterService.queryClusterByName(clusterName);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryClusterByCode() {
|
||||
Mockito.when(clusterMapper.queryByClusterCode(1L)).thenReturn(null);
|
||||
Map<String, Object> result = clusterService.queryClusterByCode(1L);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.QUERY_CLUSTER_BY_CODE_ERROR, result.get(Constants.STATUS));
|
||||
|
||||
Mockito.when(clusterMapper.queryByClusterCode(1L)).thenReturn(getCluster());
|
||||
result = clusterService.queryClusterByCode(1L);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteClusterByCode() {
|
||||
User loginUser = getGeneralUser();
|
||||
Map<String, Object> result = clusterService.deleteClusterByCode(loginUser, 1L);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS));
|
||||
|
||||
loginUser = getAdminUser();
|
||||
Mockito.when(clusterMapper.deleteByCode(1L)).thenReturn(1);
|
||||
result = clusterService.deleteClusterByCode(loginUser, 1L);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
|
||||
Mockito.when(k8sNamespaceMapper.selectCount(Mockito.any())).thenReturn(1L);
|
||||
result = clusterService.deleteClusterByCode(loginUser, 1L);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.DELETE_CLUSTER_RELATED_NAMESPACE_EXISTS, result.get(Constants.STATUS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerifyCluster() {
|
||||
Map<String, Object> result = clusterService.verifyCluster("");
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.CLUSTER_NAME_IS_NULL, result.get(Constants.STATUS));
|
||||
|
||||
Mockito.when(clusterMapper.queryByClusterName(clusterName)).thenReturn(getCluster());
|
||||
result = clusterService.verifyCluster(clusterName);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.CLUSTER_NAME_EXISTS, result.get(Constants.STATUS));
|
||||
}
|
||||
|
||||
private Cluster getCluster() {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setId(1);
|
||||
cluster.setCode(1L);
|
||||
cluster.setName(clusterName);
|
||||
cluster.setConfig(getConfig());
|
||||
cluster.setDescription(getDesc());
|
||||
cluster.setOperator(1);
|
||||
return cluster;
|
||||
}
|
||||
|
||||
/**
|
||||
* create an cluster description
|
||||
*/
|
||||
private String getDesc() {
|
||||
return "create an cluster to test ";
|
||||
}
|
||||
|
||||
/**
|
||||
* create an cluster config
|
||||
*/
|
||||
private String getConfig() {
|
||||
return "{\"k8s\":\"apiVersion: v1\\nclusters:\\n- cluster:\\n certificate-authority-data: LS0tLS1CRUdJTiBDRJUSUZJQ0FURS0tLS0tCg==\\n server: https:\\/\\/127.0.0.1:6443\\n name: kubernetes\\ncontexts:\\n- context:\\n cluster: kubernetes\\n user: kubernetes-admin\\n name: kubernetes-admin@kubernetes\\ncurrent-context: kubernetes-admin@kubernetes\\nkind: Config\\npreferences: {}\\nusers:\\n- name: kubernetes-admin\\n user:\\n client-certificate-data: LS0tLS1CRUdJTiBDRVJJ0cEhYYnBLRVktLS0tLQo=\"}\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* create general user
|
||||
*/
|
||||
private User getGeneralUser() {
|
||||
User loginUser = new User();
|
||||
loginUser.setUserType(UserType.GENERAL_USER);
|
||||
loginUser.setUserName(testUserName);
|
||||
loginUser.setId(1);
|
||||
return loginUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* create admin user
|
||||
*/
|
||||
private User getAdminUser() {
|
||||
User loginUser = new User();
|
||||
loginUser.setUserType(UserType.ADMIN_USER);
|
||||
loginUser.setUserName(testUserName);
|
||||
loginUser.setId(1);
|
||||
return loginUser;
|
||||
}
|
||||
|
||||
private List<Cluster> getList() {
|
||||
List<Cluster> list = new ArrayList<>();
|
||||
list.add(getCluster());
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,12 +17,19 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import static org.apache.dolphinscheduler.api.AssertionsHelper.assertDoesNotThrow;
|
||||
import static org.apache.dolphinscheduler.api.AssertionsHelper.assertThrowsServiceException;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.dolphinscheduler.api.dto.CommandStateCount;
|
||||
import org.apache.dolphinscheduler.api.dto.TaskCountDto;
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
|
||||
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService;
|
||||
import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.service.impl.DataAnalysisServiceImpl;
|
||||
|
|
@ -52,13 +59,11 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
|
@ -117,7 +122,7 @@ public class DataAnalysisServiceTest {
|
|||
project.setName("test");
|
||||
resultMap = new HashMap<>();
|
||||
|
||||
Mockito.when(projectMapper.queryByCode(1L)).thenReturn(project);
|
||||
when(projectMapper.queryByCode(1L)).thenReturn(project);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
|
@ -132,14 +137,11 @@ public class DataAnalysisServiceTest {
|
|||
String startDate = "2020-02-11 16:02:18";
|
||||
String endDate = "2020-02-11 16:03:18";
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
putMsg(result, Status.SUCCESS, null);
|
||||
Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong(), any())).thenReturn(result);
|
||||
Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test"));
|
||||
doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any());
|
||||
when(projectMapper.queryByCode(1L)).thenReturn(getProject("test"));
|
||||
|
||||
// SUCCESS
|
||||
result = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate, endDate);
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
assertDoesNotThrow(() -> dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate, endDate));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -148,76 +150,66 @@ public class DataAnalysisServiceTest {
|
|||
String endDate = "2020-02-11 16:03:18";
|
||||
|
||||
// checkProject false
|
||||
Map<String, Object> failResult = new HashMap<>();
|
||||
putMsg(failResult, Status.PROJECT_NOT_FOUND, 1);
|
||||
Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong(), any())).thenReturn(failResult);
|
||||
failResult = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate, endDate);
|
||||
Assertions.assertEquals(Status.PROJECT_NOT_FOUND, failResult.get(Constants.STATUS));
|
||||
doThrow(new ServiceException(Status.PROJECT_NOT_FOUND, 1)).when(projectService)
|
||||
.checkProjectAndAuthThrowException(any(), anyLong(), any());
|
||||
assertThrowsServiceException(Status.PROJECT_NOT_FOUND,
|
||||
() -> dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate, endDate));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountTaskStateByProject_paramValid() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
putMsg(result, Status.SUCCESS, null);
|
||||
Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong(), any())).thenReturn(result);
|
||||
Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test"));
|
||||
doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any());
|
||||
when(projectMapper.queryByCode(1L)).thenReturn(getProject("test"));
|
||||
|
||||
// when date in illegal format then return error message
|
||||
String startDate2 = "illegalDateString";
|
||||
String endDate2 = "illegalDateString";
|
||||
result = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate2, endDate2);
|
||||
Assertions.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result.get(Constants.STATUS));
|
||||
assertThrowsServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR,
|
||||
() -> dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate2, endDate2));
|
||||
|
||||
// when one of date in illegal format then return error message
|
||||
String startDate3 = "2020-08-28 14:13:40";
|
||||
String endDate3 = "illegalDateString";
|
||||
result = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate3, endDate3);
|
||||
Assertions.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result.get(Constants.STATUS));
|
||||
assertThrowsServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR,
|
||||
() -> dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate3, endDate3));
|
||||
|
||||
// when one of date in illegal format then return error message
|
||||
String startDate4 = "illegalDateString";
|
||||
String endDate4 = "2020-08-28 14:13:40";
|
||||
result = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate4, endDate4);
|
||||
Assertions.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result.get(Constants.STATUS));
|
||||
assertThrowsServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR,
|
||||
() -> dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate4, endDate4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountTaskStateByProject_allCountZero() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
putMsg(result, Status.SUCCESS, null);
|
||||
Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong(), any())).thenReturn(result);
|
||||
Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test"));
|
||||
doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any());
|
||||
when(projectMapper.queryByCode(1L)).thenReturn(getProject("test"));
|
||||
|
||||
// when general user doesn't have any task then return all count are 0
|
||||
user.setUserType(UserType.GENERAL_USER);
|
||||
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1,
|
||||
serviceLogger))
|
||||
.thenReturn(projectIds());
|
||||
Mockito.when(taskInstanceMapper.countTaskInstanceStateByProjectCodes(any(), any(), any())).thenReturn(
|
||||
Collections.emptyList());
|
||||
result = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, null, null);
|
||||
assertThat(result.get(Constants.DATA_LIST)).extracting("totalCount").isEqualTo(0);
|
||||
assertThat(result.get(Constants.DATA_LIST)).extracting("taskCountDtos").asList().hasSameSizeAs(
|
||||
TaskExecutionStatus.values());
|
||||
assertThat(result.get(Constants.DATA_LIST)).extracting("taskCountDtos").asList().extracting(
|
||||
"count").allMatch(count -> count.equals(0));
|
||||
when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1,
|
||||
serviceLogger)).thenReturn(projectIds());
|
||||
when(taskInstanceMapper.countTaskInstanceStateByProjectCodes(any(), any(), any()))
|
||||
.thenReturn(Collections.emptyList());
|
||||
TaskCountDto taskCountDto = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, null, null);
|
||||
assertThat(taskCountDto).extracting("totalCount").isEqualTo(0);
|
||||
assertThat(taskCountDto).extracting("taskCountDtos").asList().hasSameSizeAs(TaskExecutionStatus.values());
|
||||
assertThat(taskCountDto).extracting("taskCountDtos").asList().extracting("count")
|
||||
.allMatch(count -> count.equals(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountTaskStateByProject_noData() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
putMsg(result, Status.SUCCESS, null);
|
||||
Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong(), any())).thenReturn(result);
|
||||
Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test"));
|
||||
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1,
|
||||
doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any());
|
||||
when(projectMapper.queryByCode(1L)).thenReturn(getProject("test"));
|
||||
when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1,
|
||||
serviceLogger)).thenReturn(projectIds());
|
||||
|
||||
// when instanceStateCounter return null, then return nothing
|
||||
user.setUserType(UserType.GENERAL_USER);
|
||||
Mockito.when(taskInstanceMapper.countTaskInstanceStateByProjectCodes(any(), any(), any()))
|
||||
.thenReturn(null);
|
||||
result = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, null, null);
|
||||
Assertions.assertNull(result.get(Constants.DATA_LIST));
|
||||
when(taskInstanceMapper.countTaskInstanceStateByProjectCodes(any(), any(), any())).thenReturn(null);
|
||||
TaskCountDto taskCountDto = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, null, null);
|
||||
assertThat(taskCountDto).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -225,39 +217,31 @@ public class DataAnalysisServiceTest {
|
|||
String startDate = "2020-02-11 16:02:18";
|
||||
String endDate = "2020-02-11 16:03:18";
|
||||
|
||||
Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test"));
|
||||
when(projectMapper.queryByCode(1L)).thenReturn(getProject("test"));
|
||||
|
||||
// checkProject false
|
||||
Map<String, Object> failResult = new HashMap<>();
|
||||
putMsg(failResult, Status.PROJECT_NOT_FOUND, 1);
|
||||
Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong(), any())).thenReturn(failResult);
|
||||
failResult = dataAnalysisServiceImpl.countProcessInstanceStateByProject(user, 1, startDate, endDate);
|
||||
Assertions.assertEquals(Status.PROJECT_NOT_FOUND, failResult.get(Constants.STATUS));
|
||||
doThrow(new ServiceException(Status.PROJECT_NOT_FOUND, 1)).when(projectService)
|
||||
.checkProjectAndAuthThrowException(any(), anyLong(), any());
|
||||
assertThrowsServiceException(Status.PROJECT_NOT_FOUND,
|
||||
() -> dataAnalysisServiceImpl.countProcessInstanceStateByProject(user, 1, startDate, endDate));
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
putMsg(result, Status.SUCCESS, null);
|
||||
Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong(), any())).thenReturn(result);
|
||||
doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any());
|
||||
|
||||
// SUCCESS
|
||||
result = dataAnalysisServiceImpl.countProcessInstanceStateByProject(user, 1, startDate, endDate);
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
assertDoesNotThrow(
|
||||
() -> dataAnalysisServiceImpl.countProcessInstanceStateByProject(user, 1, startDate, endDate));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountDefinitionByUser() {
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
putMsg(result, Status.SUCCESS, null);
|
||||
|
||||
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1,
|
||||
when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1,
|
||||
serviceLogger)).thenReturn(projectIds());
|
||||
result = dataAnalysisServiceImpl.countDefinitionByUser(user, 0);
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
assertDoesNotThrow(() -> dataAnalysisServiceImpl.countDefinitionByUser(user, 0));
|
||||
|
||||
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1,
|
||||
when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1,
|
||||
serviceLogger)).thenReturn(Collections.emptySet());
|
||||
result = dataAnalysisServiceImpl.countDefinitionByUser(user, 0);
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
assertDoesNotThrow(() -> dataAnalysisServiceImpl.countDefinitionByUser(user, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -266,21 +250,17 @@ public class DataAnalysisServiceTest {
|
|||
user.setUserType(UserType.ADMIN_USER);
|
||||
user.setId(1);
|
||||
|
||||
Map<String, Object> result = dataAnalysisServiceImpl.countCommandState(user);
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
assertDoesNotThrow(() -> dataAnalysisServiceImpl.countCommandState(user));
|
||||
|
||||
// when no command found then return all count are 0
|
||||
Mockito.when(commandMapper.countCommandState(any(), any(), any())).thenReturn(Collections.emptyList());
|
||||
Mockito.when(errorCommandMapper.countCommandState(any(), any(), any())).thenReturn(Collections.emptyList());
|
||||
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1,
|
||||
when(commandMapper.countCommandState(any(), any(), any())).thenReturn(Collections.emptyList());
|
||||
when(errorCommandMapper.countCommandState(any(), any(), any())).thenReturn(Collections.emptyList());
|
||||
when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1,
|
||||
serviceLogger)).thenReturn(projectIds());
|
||||
|
||||
Map<String, Object> result5 = dataAnalysisServiceImpl.countCommandState(user);
|
||||
assertThat(result5).containsEntry(Constants.STATUS, Status.SUCCESS);
|
||||
assertThat(result5.get(Constants.DATA_LIST)).asList().extracting("errorCount")
|
||||
.allMatch(count -> count.equals(0));
|
||||
assertThat(result5.get(Constants.DATA_LIST)).asList().extracting("normalCount")
|
||||
.allMatch(count -> count.equals(0));
|
||||
List<CommandStateCount> commandStateCounts = dataAnalysisServiceImpl.countCommandState(user);
|
||||
assertThat(commandStateCounts).asList().extracting("errorCount").allMatch(count -> count.equals(0));
|
||||
assertThat(commandStateCounts).asList().extracting("normalCount").allMatch(count -> count.equals(0));
|
||||
|
||||
// when command found then return combination result
|
||||
CommandCount normalCommandCount = new CommandCount();
|
||||
|
|
@ -289,26 +269,25 @@ public class DataAnalysisServiceTest {
|
|||
CommandCount errorCommandCount = new CommandCount();
|
||||
errorCommandCount.setCommandType(CommandType.START_PROCESS);
|
||||
errorCommandCount.setCount(5);
|
||||
Mockito.when(commandMapper.countCommandState(any(), any(), any()))
|
||||
when(commandMapper.countCommandState(any(), any(), any()))
|
||||
.thenReturn(Collections.singletonList(normalCommandCount));
|
||||
Mockito.when(errorCommandMapper.countCommandState(any(), any(), any()))
|
||||
when(errorCommandMapper.countCommandState(any(), any(), any()))
|
||||
.thenReturn(Collections.singletonList(errorCommandCount));
|
||||
|
||||
Map<String, Object> result6 = dataAnalysisServiceImpl.countCommandState(user);
|
||||
commandStateCounts = dataAnalysisServiceImpl.countCommandState(user);
|
||||
|
||||
assertThat(result6).containsEntry(Constants.STATUS, Status.SUCCESS);
|
||||
CommandStateCount commandStateCount = new CommandStateCount();
|
||||
commandStateCount.setCommandState(CommandType.START_PROCESS);
|
||||
commandStateCount.setNormalCount(10);
|
||||
commandStateCount.setErrorCount(5);
|
||||
assertThat(result6.get(Constants.DATA_LIST)).asList().containsOnlyOnce(commandStateCount);
|
||||
assertThat(commandStateCounts).asList().containsOnlyOnce(commandStateCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountQueueState() {
|
||||
// when project check success when return all count are 0
|
||||
Map<String, Object> result2 = dataAnalysisServiceImpl.countQueueState(user);
|
||||
assertThat(result2.get(Constants.DATA_LIST)).extracting("taskQueue", "taskKill")
|
||||
Map<String, Integer> stringIntegerMap = dataAnalysisServiceImpl.countQueueState(user);
|
||||
assertThat(stringIntegerMap).extracting("taskQueue", "taskKill")
|
||||
.isNotEmpty()
|
||||
.allMatch(count -> count.equals(0));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,14 +17,16 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import static org.apache.dolphinscheduler.api.AssertionsHelper.assertDoesNotThrow;
|
||||
import static org.apache.dolphinscheduler.api.AssertionsHelper.assertThrowsServiceException;
|
||||
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.DATASOURCE;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService;
|
||||
import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.service.impl.DataSourceServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.DataSourceConstants;
|
||||
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
|
|
@ -95,9 +97,9 @@ public class DataSourceServiceTest {
|
|||
private ResourcePermissionCheckService resourcePermissionCheckService;
|
||||
|
||||
private void passResourcePermissionCheckService() {
|
||||
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(Mockito.any(), Mockito.anyInt(),
|
||||
when(resourcePermissionCheckService.operationPermissionCheck(Mockito.any(), Mockito.anyInt(),
|
||||
Mockito.anyString(), Mockito.any())).thenReturn(true);
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(Mockito.any(), Mockito.any(),
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(Mockito.any(), Mockito.any(),
|
||||
Mockito.anyInt(), Mockito.any())).thenReturn(true);
|
||||
}
|
||||
|
||||
|
|
@ -118,28 +120,28 @@ public class DataSourceServiceTest {
|
|||
postgreSqlDatasourceParam.setName(dataSourceName);
|
||||
|
||||
// USER_NO_OPERATION_PERM
|
||||
Result result = dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam);
|
||||
Assertions.assertEquals(Status.USER_NO_OPERATION_PERM.getCode(), result.getCode().intValue());
|
||||
assertThrowsServiceException(Status.USER_NO_OPERATION_PERM,
|
||||
() -> dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam));
|
||||
|
||||
// DATASOURCE_EXIST
|
||||
List<DataSource> dataSourceList = new ArrayList<>();
|
||||
DataSource dataSource = new DataSource();
|
||||
dataSource.setName(dataSourceName);
|
||||
dataSourceList.add(dataSource);
|
||||
Mockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName.trim())).thenReturn(dataSourceList);
|
||||
when(dataSourceMapper.queryDataSourceByName(dataSourceName.trim())).thenReturn(dataSourceList);
|
||||
passResourcePermissionCheckService();
|
||||
Result dataSourceExitsResult = dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam);
|
||||
Assertions.assertEquals(Status.DATASOURCE_EXIST.getCode(), dataSourceExitsResult.getCode().intValue());
|
||||
|
||||
assertThrowsServiceException(Status.DATASOURCE_EXIST,
|
||||
() -> dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam));
|
||||
|
||||
try (
|
||||
MockedStatic<DataSourceClientProvider> mockedStaticDataSourceClientProvider =
|
||||
Mockito.mockStatic(DataSourceClientProvider.class)) {
|
||||
|
||||
Mockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName.trim())).thenReturn(null);
|
||||
when(dataSourceMapper.queryDataSourceByName(dataSourceName.trim())).thenReturn(null);
|
||||
|
||||
// SUCCESS
|
||||
Result success = dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam);
|
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), success.getCode().intValue());
|
||||
assertDoesNotThrow(() -> dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -153,6 +155,7 @@ public class DataSourceServiceTest {
|
|||
String dataSourceUpdateName = "dataSource01-update";
|
||||
|
||||
PostgreSQLDataSourceParamDTO postgreSqlDatasourceParam = new PostgreSQLDataSourceParamDTO();
|
||||
postgreSqlDatasourceParam.setId(dataSourceId);
|
||||
postgreSqlDatasourceParam.setDatabase(dataSourceName);
|
||||
postgreSqlDatasourceParam.setNote(dataSourceDesc);
|
||||
postgreSqlDatasourceParam.setHost("172.16.133.200");
|
||||
|
|
@ -163,18 +166,16 @@ public class DataSourceServiceTest {
|
|||
postgreSqlDatasourceParam.setName(dataSourceUpdateName);
|
||||
|
||||
// RESOURCE_NOT_EXIST
|
||||
Mockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(null);
|
||||
Result resourceNotExits =
|
||||
dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam);
|
||||
Assertions.assertEquals(Status.RESOURCE_NOT_EXIST.getCode(), resourceNotExits.getCode().intValue());
|
||||
when(dataSourceMapper.selectById(dataSourceId)).thenReturn(null);
|
||||
assertThrowsServiceException(Status.RESOURCE_NOT_EXIST,
|
||||
() -> dataSourceService.updateDataSource(loginUser, postgreSqlDatasourceParam));
|
||||
|
||||
// USER_NO_OPERATION_PERM
|
||||
DataSource dataSource = new DataSource();
|
||||
dataSource.setUserId(0);
|
||||
Mockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource);
|
||||
Result userNoOperationPerm =
|
||||
dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam);
|
||||
Assertions.assertEquals(Status.USER_NO_OPERATION_PERM.getCode(), userNoOperationPerm.getCode().intValue());
|
||||
when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource);
|
||||
assertThrowsServiceException(Status.USER_NO_OPERATION_PERM,
|
||||
() -> dataSourceService.updateDataSource(loginUser, postgreSqlDatasourceParam));
|
||||
|
||||
// DATASOURCE_EXIST
|
||||
dataSource.setName(dataSourceName);
|
||||
|
|
@ -186,23 +187,21 @@ public class DataSourceServiceTest {
|
|||
anotherDataSource.setName(dataSourceUpdateName);
|
||||
List<DataSource> dataSourceList = new ArrayList<>();
|
||||
dataSourceList.add(anotherDataSource);
|
||||
Mockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource);
|
||||
Mockito.when(dataSourceMapper.queryDataSourceByName(postgreSqlDatasourceParam.getName()))
|
||||
when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource);
|
||||
when(dataSourceMapper.queryDataSourceByName(postgreSqlDatasourceParam.getName()))
|
||||
.thenReturn(dataSourceList);
|
||||
passResourcePermissionCheckService();
|
||||
Result dataSourceNameExist =
|
||||
dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam);
|
||||
Assertions.assertEquals(Status.DATASOURCE_EXIST.getCode(), dataSourceNameExist.getCode().intValue());
|
||||
assertThrowsServiceException(Status.DATASOURCE_EXIST,
|
||||
() -> dataSourceService.updateDataSource(loginUser, postgreSqlDatasourceParam));
|
||||
|
||||
try (
|
||||
MockedStatic<DataSourceClientProvider> mockedStaticDataSourceClientProvider =
|
||||
Mockito.mockStatic(DataSourceClientProvider.class)) {
|
||||
// DATASOURCE_CONNECT_FAILED
|
||||
Mockito.when(dataSourceMapper.queryDataSourceByName(postgreSqlDatasourceParam.getName())).thenReturn(null);
|
||||
when(dataSourceMapper.queryDataSourceByName(postgreSqlDatasourceParam.getName())).thenReturn(null);
|
||||
|
||||
// SUCCESS
|
||||
Result success = dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam);
|
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), success.getCode().intValue());
|
||||
assertDoesNotThrow(() -> dataSourceService.updateDataSource(loginUser, postgreSqlDatasourceParam));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -221,37 +220,34 @@ public class DataSourceServiceTest {
|
|||
@Test
|
||||
public void connectionTest() {
|
||||
int dataSourceId = -1;
|
||||
Mockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(null);
|
||||
Result result = dataSourceService.connectionTest(dataSourceId);
|
||||
Assertions.assertEquals(Status.RESOURCE_NOT_EXIST.getCode(), result.getCode().intValue());
|
||||
when(dataSourceMapper.selectById(dataSourceId)).thenReturn(null);
|
||||
assertThrowsServiceException(Status.RESOURCE_NOT_EXIST, () -> dataSourceService.connectionTest(dataSourceId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteTest() {
|
||||
User loginUser = getAdminUser();
|
||||
int dataSourceId = 1;
|
||||
Result result = new Result();
|
||||
// resource not exist
|
||||
dataSourceService.putMsg(result, Status.RESOURCE_NOT_EXIST);
|
||||
Mockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(null);
|
||||
Assertions.assertEquals(result.getCode(), dataSourceService.delete(loginUser, dataSourceId).getCode());
|
||||
when(dataSourceMapper.selectById(dataSourceId)).thenReturn(null);
|
||||
assertThrowsServiceException(Status.RESOURCE_NOT_EXIST,
|
||||
() -> dataSourceService.delete(loginUser, dataSourceId));
|
||||
|
||||
// user no operation perm
|
||||
dataSourceService.putMsg(result, Status.USER_NO_OPERATION_PERM);
|
||||
DataSource dataSource = new DataSource();
|
||||
dataSource.setUserId(0);
|
||||
Mockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource);
|
||||
Assertions.assertEquals(result.getCode(), dataSourceService.delete(loginUser, dataSourceId).getCode());
|
||||
when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource);
|
||||
assertThrowsServiceException(Status.USER_NO_OPERATION_PERM,
|
||||
() -> dataSourceService.delete(loginUser, dataSourceId));
|
||||
|
||||
// success
|
||||
dataSourceService.putMsg(result, Status.SUCCESS);
|
||||
dataSource.setUserId(-1);
|
||||
loginUser.setUserType(UserType.ADMIN_USER);
|
||||
loginUser.setId(1);
|
||||
dataSource.setId(22);
|
||||
passResourcePermissionCheckService();
|
||||
Mockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource);
|
||||
Assertions.assertEquals(result.getCode(), dataSourceService.delete(loginUser, dataSourceId).getCode());
|
||||
when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource);
|
||||
assertDoesNotThrow(() -> dataSourceService.delete(loginUser, dataSourceId));
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -261,13 +257,13 @@ public class DataSourceServiceTest {
|
|||
loginUser.setId(1);
|
||||
loginUser.setUserType(UserType.ADMIN_USER);
|
||||
int userId = 3;
|
||||
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE,
|
||||
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE,
|
||||
loginUser.getId(), null, baseServiceLogger)).thenReturn(true);
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE, null, 0,
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE, null, 0,
|
||||
baseServiceLogger)).thenReturn(true);
|
||||
// test admin user
|
||||
Mockito.when(dataSourceMapper.queryAuthedDatasource(userId)).thenReturn(getSingleDataSourceList());
|
||||
Mockito.when(dataSourceMapper.queryDatasourceExceptUserId(userId)).thenReturn(getDataSourceList());
|
||||
when(dataSourceMapper.queryAuthedDatasource(userId)).thenReturn(getSingleDataSourceList());
|
||||
when(dataSourceMapper.queryDatasourceExceptUserId(userId)).thenReturn(getDataSourceList());
|
||||
List<DataSource> dataSources = dataSourceService.unAuthDatasource(loginUser, userId);
|
||||
logger.info(dataSources.toString());
|
||||
Assertions.assertTrue(CollectionUtils.isNotEmpty(dataSources));
|
||||
|
|
@ -275,7 +271,7 @@ public class DataSourceServiceTest {
|
|||
// test non-admin user
|
||||
loginUser.setId(2);
|
||||
loginUser.setUserType(UserType.GENERAL_USER);
|
||||
Mockito.when(dataSourceMapper.selectByMap(Collections.singletonMap("user_id", loginUser.getId())))
|
||||
when(dataSourceMapper.selectByMap(Collections.singletonMap("user_id", loginUser.getId())))
|
||||
.thenReturn(getDataSourceList());
|
||||
dataSources = dataSourceService.unAuthDatasource(loginUser, userId);
|
||||
logger.info(dataSources.toString());
|
||||
|
|
@ -290,7 +286,7 @@ public class DataSourceServiceTest {
|
|||
int userId = 3;
|
||||
|
||||
// test admin user
|
||||
Mockito.when(dataSourceMapper.queryAuthedDatasource(userId)).thenReturn(getSingleDataSourceList());
|
||||
when(dataSourceMapper.queryAuthedDatasource(userId)).thenReturn(getSingleDataSourceList());
|
||||
List<DataSource> dataSources = dataSourceService.authedDatasource(loginUser, userId);
|
||||
logger.info(dataSources.toString());
|
||||
Assertions.assertTrue(CollectionUtils.isNotEmpty(dataSources));
|
||||
|
|
@ -309,12 +305,12 @@ public class DataSourceServiceTest {
|
|||
loginUser.setUserType(UserType.GENERAL_USER);
|
||||
Set<Integer> dataSourceIds = new HashSet<>();
|
||||
dataSourceIds.add(1);
|
||||
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.DATASOURCE,
|
||||
when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.DATASOURCE,
|
||||
loginUser.getId(), dataSourceServiceLogger)).thenReturn(dataSourceIds);
|
||||
|
||||
DataSource dataSource = new DataSource();
|
||||
dataSource.setType(DbType.MYSQL);
|
||||
Mockito.when(dataSourceMapper.selectBatchIds(dataSourceIds)).thenReturn(Collections.singletonList(dataSource));
|
||||
when(dataSourceMapper.selectBatchIds(dataSourceIds)).thenReturn(Collections.singletonList(dataSource));
|
||||
List<DataSource> list =
|
||||
dataSourceService.queryDataSourceList(loginUser, DbType.MYSQL.ordinal());
|
||||
Assertions.assertNotNull(list);
|
||||
|
|
@ -325,14 +321,14 @@ public class DataSourceServiceTest {
|
|||
User loginUser = new User();
|
||||
loginUser.setUserType(UserType.GENERAL_USER);
|
||||
String dataSourceName = "dataSource1";
|
||||
Mockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName)).thenReturn(getDataSourceList());
|
||||
Result result = dataSourceService.verifyDataSourceName(dataSourceName);
|
||||
Assertions.assertEquals(Status.DATASOURCE_EXIST.getMsg(), result.getMsg());
|
||||
when(dataSourceMapper.queryDataSourceByName(dataSourceName)).thenReturn(getDataSourceList());
|
||||
assertThrowsServiceException(Status.DATASOURCE_EXIST,
|
||||
() -> dataSourceService.verifyDataSourceName(dataSourceName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryDataSourceTest() {
|
||||
Mockito.when(dataSourceMapper.selectById(Mockito.anyInt())).thenReturn(null);
|
||||
when(dataSourceMapper.selectById(Mockito.anyInt())).thenReturn(null);
|
||||
User loginUser = new User();
|
||||
loginUser.setUserType(UserType.GENERAL_USER);
|
||||
loginUser.setId(2);
|
||||
|
|
@ -343,10 +339,10 @@ public class DataSourceServiceTest {
|
|||
}
|
||||
|
||||
DataSource dataSource = getOracleDataSource(1);
|
||||
Mockito.when(dataSourceMapper.selectById(Mockito.anyInt())).thenReturn(dataSource);
|
||||
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE,
|
||||
when(dataSourceMapper.selectById(Mockito.anyInt())).thenReturn(dataSource);
|
||||
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE,
|
||||
loginUser.getId(), DATASOURCE, baseServiceLogger)).thenReturn(true);
|
||||
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE,
|
||||
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE,
|
||||
new Object[]{dataSource.getId()}, loginUser.getId(), baseServiceLogger)).thenReturn(true);
|
||||
BaseDataSourceParamDTO paramDTO = dataSourceService.queryDataSource(dataSource.getId(), loginUser);
|
||||
Assertions.assertNotNull(paramDTO);
|
||||
|
|
@ -506,15 +502,14 @@ public class DataSourceServiceTest {
|
|||
Mockito.mockStatic(DataSourceUtils.class)) {
|
||||
DataSourceProcessor dataSourceProcessor = Mockito.mock(DataSourceProcessor.class);
|
||||
|
||||
Mockito.when(DataSourceUtils.getDatasourceProcessor(Mockito.any())).thenReturn(dataSourceProcessor);
|
||||
Mockito.when(dataSourceProcessor.checkDataSourceConnectivity(Mockito.any())).thenReturn(false);
|
||||
when(DataSourceUtils.getDatasourceProcessor(Mockito.any())).thenReturn(dataSourceProcessor);
|
||||
when(dataSourceProcessor.checkDataSourceConnectivity(Mockito.any())).thenReturn(false);
|
||||
|
||||
Result result = dataSourceService.checkConnection(dataSourceType, connectionParam);
|
||||
Assertions.assertEquals(Status.CONNECTION_TEST_FAILURE.getCode(), result.getCode().intValue());
|
||||
assertThrowsServiceException(Status.CONNECTION_TEST_FAILURE,
|
||||
() -> dataSourceService.checkConnection(dataSourceType, connectionParam));
|
||||
|
||||
Mockito.when(dataSourceProcessor.checkDataSourceConnectivity(Mockito.any())).thenReturn(true);
|
||||
result = dataSourceService.checkConnection(dataSourceType, connectionParam);
|
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
|
||||
when(dataSourceProcessor.checkDataSourceConnectivity(Mockito.any())).thenReturn(true);
|
||||
assertDoesNotThrow(() -> dataSourceService.checkConnection(dataSourceType, connectionParam));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -523,7 +518,7 @@ public class DataSourceServiceTest {
|
|||
DataSource dataSource = getOracleDataSource();
|
||||
int datasourceId = 1;
|
||||
dataSource.setId(datasourceId);
|
||||
Mockito.when(dataSourceMapper.selectById(datasourceId)).thenReturn(null);
|
||||
when(dataSourceMapper.selectById(datasourceId)).thenReturn(null);
|
||||
|
||||
try {
|
||||
dataSourceService.getDatabases(datasourceId);
|
||||
|
|
@ -531,7 +526,7 @@ public class DataSourceServiceTest {
|
|||
Assertions.assertTrue(e.getMessage().contains(Status.QUERY_DATASOURCE_ERROR.getMsg()));
|
||||
}
|
||||
|
||||
Mockito.when(dataSourceMapper.selectById(datasourceId)).thenReturn(dataSource);
|
||||
when(dataSourceMapper.selectById(datasourceId)).thenReturn(dataSource);
|
||||
MySQLConnectionParam connectionParam = new MySQLConnectionParam();
|
||||
Connection connection = Mockito.mock(Connection.class);
|
||||
MockedStatic<DataSourceUtils> dataSourceUtils = Mockito.mockStatic(DataSourceUtils.class);
|
||||
|
|
|
|||
|
|
@ -17,16 +17,15 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import static org.apache.dolphinscheduler.api.AssertionsHelper.assertDoesNotThrow;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.dolphinscheduler.api.ApiApplicationServer;
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService;
|
||||
import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.service.impl.DqExecuteResultServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
import org.apache.dolphinscheduler.common.utils.DateUtils;
|
||||
|
|
@ -39,7 +38,6 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
|
|
@ -90,12 +88,11 @@ public class DqExecuteResultServiceTest {
|
|||
Page<DqExecuteResult> page = new Page<>(1, 10);
|
||||
page.setTotal(1);
|
||||
page.setRecords(getExecuteResultList());
|
||||
when(dqExecuteResultMapper.queryResultListPaging(
|
||||
any(IPage.class), eq(""), eq(loginUser), any(), eq(ruleType), eq(start), eq(end))).thenReturn(page);
|
||||
when(dqExecuteResultMapper.queryResultListPaging(any(IPage.class), eq(""), eq(loginUser), any(), eq(ruleType),
|
||||
eq(start), eq(end))).thenReturn(page);
|
||||
|
||||
Result result = dqExecuteResultService.queryResultListPaging(
|
||||
loginUser, searchVal, 1, 0, "2020-01-01 00:00:00", "2020-01-02 00:00:00", 1, 10);
|
||||
Assertions.assertEquals(Integer.valueOf(Status.SUCCESS.getCode()), result.getCode());
|
||||
assertDoesNotThrow(() -> dqExecuteResultService.queryResultListPaging(loginUser, searchVal, 1, 0,
|
||||
"2020-01-01 00:00:00", "2020-01-02 00:00:00", 1, 10));
|
||||
}
|
||||
|
||||
public List<DqExecuteResult> getExecuteResultList() {
|
||||
|
|
|
|||
|
|
@ -17,17 +17,15 @@
|
|||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import static org.apache.dolphinscheduler.api.AssertionsHelper.assertDoesNotThrow;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.dolphinscheduler.api.ApiApplicationServer;
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService;
|
||||
import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.service.impl.DqRuleServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
import org.apache.dolphinscheduler.common.utils.DateUtils;
|
||||
|
|
@ -51,7 +49,6 @@ import org.apache.dolphinscheduler.spi.params.base.FormType;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
@ -109,22 +106,20 @@ public class DqRuleServiceTest {
|
|||
+ "\"statistics_execute_sql\",\"name\":\"统计值计算SQL\",\"type\":\"input\",\"title\":"
|
||||
+ "\"统计值计算SQL\",\"validate\":[{\"required\":true,\"type\":\"string\",\"trigger\":\"blur\"}]}]";
|
||||
when(dqRuleInputEntryMapper.getRuleInputEntryList(1)).thenReturn(getRuleInputEntryList());
|
||||
Map<String, Object> result = dqRuleService.getRuleFormCreateJsonById(1);
|
||||
Assertions.assertEquals(json, result.get(Constants.DATA_LIST));
|
||||
String ruleFormCreateJsonById = dqRuleService.getRuleFormCreateJsonById(1);
|
||||
Assertions.assertEquals(json, ruleFormCreateJsonById);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryAllRuleList() {
|
||||
when(dqRuleMapper.selectList(new QueryWrapper<>())).thenReturn(getRuleList());
|
||||
Map<String, Object> result = dqRuleService.queryAllRuleList();
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
assertDoesNotThrow(() -> dqRuleService.queryAllRuleList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDatasourceOptionsById() {
|
||||
when(dataSourceMapper.listAllDataSourceByType(DbType.MYSQL.getCode())).thenReturn(dataSourceList());
|
||||
Map<String, Object> result = dqRuleService.queryAllRuleList();
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
assertDoesNotThrow(() -> dqRuleService.queryAllRuleList());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -146,15 +141,14 @@ public class DqRuleServiceTest {
|
|||
page.setTotal(1);
|
||||
page.setRecords(getRuleList());
|
||||
|
||||
when(dqRuleMapper.queryRuleListPaging(
|
||||
any(IPage.class), eq(""), eq(ruleType), eq(start), eq(end))).thenReturn(page);
|
||||
when(dqRuleMapper.queryRuleListPaging(any(IPage.class), eq(""), eq(ruleType), eq(start), eq(end)))
|
||||
.thenReturn(page);
|
||||
|
||||
when(dqRuleInputEntryMapper.getRuleInputEntryList(1)).thenReturn(getRuleInputEntryList());
|
||||
when(dqRuleExecuteSqlMapper.getExecuteSqlList(1)).thenReturn(getRuleExecuteSqlList());
|
||||
|
||||
Result result = dqRuleService.queryRuleListPaging(
|
||||
loginUser, searchVal, 0, "2020-01-01 00:00:00", "2020-01-02 00:00:00", 1, 10);
|
||||
Assertions.assertEquals(Integer.valueOf(Status.SUCCESS.getCode()), result.getCode());
|
||||
assertDoesNotThrow(() -> dqRuleService.queryRuleListPaging(loginUser, searchVal, 0, "2020-01-01 00:00:00",
|
||||
"2020-01-02 00:00:00", 1, 10));
|
||||
}
|
||||
|
||||
private List<DataSource> dataSourceList() {
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue