mirror of
https://gitee.com/dolphinscheduler/DolphinScheduler.git
synced 2024-12-03 04:39:00 +08:00
update QueueController and QueueService
This commit is contained in:
parent
022b49b45d
commit
5d41d66427
@ -141,5 +141,30 @@ public class QueueController extends BaseController{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* verify queue and queue name
|
||||
*
|
||||
* @param loginUser
|
||||
* @param queue
|
||||
* @param queueName
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/verify-queue")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public Result verifyQueue(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value ="queue") String queue,
|
||||
@RequestParam(value ="queueName") String queueName
|
||||
) {
|
||||
|
||||
try{
|
||||
logger.info("login user {}, verfiy queue: {} queue name: {}",
|
||||
loginUser.getUserName(),queue,queueName);
|
||||
return queueService.verifyQueue(queue,queueName);
|
||||
}catch (Exception e){
|
||||
logger.error(VERIFY_QUEUE_ERROR.getMsg(),e);
|
||||
return error(Status.VERIFY_QUEUE_ERROR.getCode(), Status.VERIFY_QUEUE_ERROR.getMsg());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -19,10 +19,13 @@ package cn.escheduler.api.service;
|
||||
import cn.escheduler.api.enums.Status;
|
||||
import cn.escheduler.api.utils.Constants;
|
||||
import cn.escheduler.api.utils.PageInfo;
|
||||
import cn.escheduler.api.utils.Result;
|
||||
import cn.escheduler.dao.mapper.QueueMapper;
|
||||
import cn.escheduler.dao.model.Queue;
|
||||
import cn.escheduler.dao.model.User;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -37,6 +40,7 @@ import java.util.Map;
|
||||
@Service
|
||||
public class QueueService extends BaseService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TenantService.class);
|
||||
|
||||
@Autowired
|
||||
private QueueMapper queueMapper;
|
||||
@ -103,12 +107,22 @@ public class QueueService extends BaseService {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (checkQueueExists(queue)) {
|
||||
if(StringUtils.isEmpty(queue)){
|
||||
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, queue);
|
||||
return result;
|
||||
}
|
||||
|
||||
if(StringUtils.isEmpty(queueName)){
|
||||
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, queueName);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (checkQueueExist(queue)) {
|
||||
putMsg(result, Status.QUEUE_EXIST, queue);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (checkQueueExists(queueName)) {
|
||||
if (checkQueueNameExist(queueName)) {
|
||||
putMsg(result, Status.QUEUE_NAME_EXIST, queueName);
|
||||
return result;
|
||||
}
|
||||
@ -142,27 +156,38 @@ public class QueueService extends BaseService {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Queue queueObj = queueMapper.queryById(id);
|
||||
if (queueObj == null) {
|
||||
putMsg(result, Status.QUEUE_NOT_EXIST, id);
|
||||
return result;
|
||||
}
|
||||
|
||||
//update queue
|
||||
// whether queue and queueName is changed
|
||||
if (queue.equals(queueObj.getQueue()) && queueName.equals(queueObj.getQueueName())) {
|
||||
putMsg(result, Status.NEED_NOT_UPDATE_QUEUE);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(queue)) {
|
||||
if (!queue.equals(queueObj.getQueue()) && checkQueueExists(queue)) {
|
||||
// check queue is exist
|
||||
if (!queue.equals(queueObj.getQueue())) {
|
||||
if(checkQueueExist(queue)){
|
||||
putMsg(result, Status.QUEUE_EXIST, queue);
|
||||
return result;
|
||||
}
|
||||
queueObj.setQueue(queue);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(queueName)) {
|
||||
queueObj.setQueueName(queueName);
|
||||
}
|
||||
Date now = new Date();
|
||||
|
||||
// check queueName is exist
|
||||
if (!queueName.equals(queueObj.getQueueName())) {
|
||||
if(checkQueueNameExist(queueName)){
|
||||
putMsg(result, Status.QUEUE_NAME_EXIST, queueName);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// update queue
|
||||
Date now = new Date();
|
||||
queueObj.setQueue(queue);
|
||||
queueObj.setQueueName(queueName);
|
||||
queueObj.setUpdateTime(now);
|
||||
|
||||
queueMapper.update(queueObj);
|
||||
@ -171,15 +196,59 @@ public class QueueService extends BaseService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* verify queue and queueName
|
||||
*
|
||||
* @param queue
|
||||
* @param queueName
|
||||
* @return
|
||||
*/
|
||||
public Result verifyQueue(String queue, String queueName) {
|
||||
Result result=new Result();
|
||||
|
||||
if (StringUtils.isEmpty(queue)) {
|
||||
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, queue);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(queueName)) {
|
||||
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, queueName);
|
||||
return result;
|
||||
}
|
||||
if(checkQueueExist(queue)){
|
||||
logger.error("queue {} has exist, can't create again.", queue);
|
||||
putMsg(result, Status.QUEUE_EXIST, queue);
|
||||
return result;
|
||||
}
|
||||
|
||||
if(checkQueueNameExist(queueName)){
|
||||
logger.error("queueName {} has exist, can't create again.", queueName);
|
||||
putMsg(result, Status.QUEUE_NAME_EXIST, queueName);
|
||||
return result;
|
||||
}
|
||||
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* check queue exists
|
||||
* check queue exist
|
||||
*
|
||||
* @param queue
|
||||
* @return
|
||||
*/
|
||||
private boolean checkQueueExists(String queue) {
|
||||
private boolean checkQueueExist(String queue) {
|
||||
return queueMapper.queryByQueue(queue) == null ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* check queue name exist
|
||||
*
|
||||
* @param queueName
|
||||
* @return
|
||||
*/
|
||||
private boolean checkQueueNameExist(String queueName) {
|
||||
return queueMapper.queryByQueueName(queueName) == null ? false : true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -93,8 +93,8 @@ public class QueueControllerTest {
|
||||
public void createQueue() throws Exception {
|
||||
|
||||
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
|
||||
paramsMap.add("queue","ait1111");
|
||||
paramsMap.add("queueName","aitName");
|
||||
paramsMap.add("queue","ait111134");
|
||||
paramsMap.add("queueName","aitName1");
|
||||
|
||||
MvcResult mvcResult = mockMvc.perform(post("/queue/create")
|
||||
.header("sessionId", "d4541e0d-0349-4f05-9c68-300176cd3c91")
|
||||
@ -112,7 +112,7 @@ public class QueueControllerTest {
|
||||
|
||||
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
|
||||
paramsMap.add("id","2");
|
||||
paramsMap.add("queue","ait1");
|
||||
paramsMap.add("queue","ait12");
|
||||
paramsMap.add("queueName","aitName");
|
||||
|
||||
MvcResult mvcResult = mockMvc.perform(post("/queue/update")
|
||||
@ -125,4 +125,22 @@ public class QueueControllerTest {
|
||||
//Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyQueue() throws Exception {
|
||||
|
||||
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
|
||||
paramsMap.add("queue","ait123");
|
||||
paramsMap.add("queueName","aitName");
|
||||
|
||||
MvcResult mvcResult = mockMvc.perform(post("/queue/verify-queue")
|
||||
.header("sessionId", "d4541e0d-0349-4f05-9c68-300176cd3c91")
|
||||
.params(paramsMap))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
|
||||
.andReturn();
|
||||
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
//Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user