From f5662e2d1ca906f5ed6c200fe9d90e811b92e5ad Mon Sep 17 00:00:00 2001 From: ligang Date: Thu, 11 Apr 2019 16:24:38 +0800 Subject: [PATCH 01/15] add createTime and updateTime --- .../java/cn/escheduler/dao/model/Queue.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/escheduler-dao/src/main/java/cn/escheduler/dao/model/Queue.java b/escheduler-dao/src/main/java/cn/escheduler/dao/model/Queue.java index d9a6f37b98..d03d40a411 100644 --- a/escheduler-dao/src/main/java/cn/escheduler/dao/model/Queue.java +++ b/escheduler-dao/src/main/java/cn/escheduler/dao/model/Queue.java @@ -16,6 +16,8 @@ */ package cn.escheduler.dao.model; +import java.util.Date; + /** * queue */ @@ -34,6 +36,15 @@ public class Queue { */ private String queue; + /** + * create time + */ + private Date createTime; + /** + * update time + */ + private Date updateTime; + public int getId() { return id; } @@ -58,12 +69,30 @@ public class Queue { this.queue = queue; } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + @Override public String toString() { return "Queue{" + "id=" + id + ", queueName='" + queueName + '\'' + ", queue='" + queue + '\'' + + ", createTime=" + createTime + + ", updateTime=" + updateTime + '}'; } } From ffbb771cbfc79bd8a7c75a56516230aa38b5508f Mon Sep 17 00:00:00 2001 From: ligang Date: Thu, 11 Apr 2019 16:27:26 +0800 Subject: [PATCH 02/15] =?UTF-8?q?add=20CREATE=5FQUEUE=5FERROR=E3=80=81QUEU?= =?UTF-8?q?E=5FNOT=5FEXIST=E3=80=81QUEUE=5FEXIST=E3=80=81UPDATE=5FQUEUE=5F?= =?UTF-8?q?ERROR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/escheduler/api/enums/Status.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java b/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java index 265dac3d22..b99d3fa743 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java @@ -149,6 +149,10 @@ public enum Status { TENANT_CODE_HAS_ALREADY_EXISTS(10124,"tenant code has already exists"), IP_IS_EMPTY(10125,"ip is empty"), SCHEDULE_CRON_REALEASE_NEED_NOT_CHANGE(10126, "schedule release is already {0}"), + CREATE_QUEUE_ERROR(10127, "create queue error"), + QUEUE_NOT_EXIST(10128, "queue {0} not exists"), + QUEUE_EXIST(10129, "queue already exists"), + UPDATE_QUEUE_ERROR(10130, "update queue error"), UDF_FUNCTION_NOT_EXIST(20001, "UDF function not found"), From 303e1b751aa6cf77411ba06298b7f84e245417ca Mon Sep 17 00:00:00 2001 From: ligang Date: Thu, 11 Apr 2019 16:30:58 +0800 Subject: [PATCH 03/15] update QueueMapper and QueueMapperProvider --- .../cn/escheduler/dao/mapper/QueueMapper.java | 32 +++++++++- .../dao/mapper/QueueMapperProvider.java | 62 +++++++++++++++++-- 2 files changed, 87 insertions(+), 7 deletions(-) diff --git a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapper.java b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapper.java index 534666c463..b5e8ad99be 100644 --- a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapper.java +++ b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapper.java @@ -20,6 +20,7 @@ import cn.escheduler.dao.model.Queue; import org.apache.ibatis.annotations.*; import org.apache.ibatis.type.JdbcType; +import java.sql.Timestamp; import java.util.List; /** @@ -64,7 +65,9 @@ public interface QueueMapper { */ @Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER), @Result(property = "queueName", column = "queue_name", javaType = String.class, jdbcType = JdbcType.VARCHAR), - @Result(property = "queue", column = "queue", javaType = String.class, jdbcType = JdbcType.VARCHAR) + @Result(property = "queue", column = "queue", javaType = String.class, jdbcType = JdbcType.VARCHAR), + @Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE), + @Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE) }) @SelectProvider(type = QueueMapperProvider.class, method = "queryById") Queue queryById(@Param("queueId") int queueId); @@ -76,13 +79,38 @@ public interface QueueMapper { */ @Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER), @Result(property = "queueName", column = "queue_name", javaType = String.class, jdbcType = JdbcType.VARCHAR), - @Result(property = "queue", column = "queue", javaType = String.class, jdbcType = JdbcType.VARCHAR) + @Result(property = "queue", column = "queue", javaType = String.class, jdbcType = JdbcType.VARCHAR), + @Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE), + @Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE) }) @SelectProvider(type = QueueMapperProvider.class, method = "queryAllQueue") List queryAllQueue(); + /** + * query all queue list + * @return + */ + @Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER), + @Result(property = "queueName", column = "queue_name", javaType = String.class, jdbcType = JdbcType.VARCHAR), + @Result(property = "queue", column = "queue", javaType = String.class, jdbcType = JdbcType.VARCHAR), + @Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE), + @Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE) + }) + @SelectProvider(type = QueueMapperProvider.class, method = "queryQueuePaging") + List queryQueuePaging(@Param("searchVal") String searchVal, + @Param("offset") Integer offset, + @Param("pageSize") Integer pageSize); + /** + * count queue by search value + * @param searchVal + * @return + */ + @SelectProvider(type = QueueMapperProvider.class, method = "countQueuePaging") + Integer countQueuePaging(@Param("searchVal") String searchVal); + @SelectProvider(type = QueueMapperProvider.class, method = "queryByQueue") + Queue queryByQueue(@Param("queue") String queue); } diff --git a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapperProvider.java b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapperProvider.java index ee829f1557..e3adbaa1e6 100644 --- a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapperProvider.java +++ b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapperProvider.java @@ -16,6 +16,7 @@ */ package cn.escheduler.dao.mapper; +import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.jdbc.SQL; import java.util.Map; @@ -39,7 +40,8 @@ public class QueueMapperProvider { INSERT_INTO(TABLE_NAME); VALUES("`queue_name`", "#{queue.queueName}"); VALUES("`queue`", "#{queue.queue}"); - + VALUES("`create_time`", "#{queue.createTime}"); + VALUES("`update_time`", "#{queue.updateTime}"); } }.toString(); } @@ -73,6 +75,7 @@ public class QueueMapperProvider { SET("`queue_name`=#{queue.queueName}"); SET("`queue`=#{queue.queue}"); + SET("`update_time`=#{queue.updateTime}"); WHERE("`id`=#{queue.id}"); } @@ -80,10 +83,6 @@ public class QueueMapperProvider { } - - - - /** * query queue by id * @@ -117,5 +116,58 @@ public class QueueMapperProvider { }.toString(); } + /** + * count queue by search value + * @param parameter + * @return + */ + public String countQueuePaging(Map parameter) { + return new SQL() {{ + SELECT("count(0)"); + FROM(TABLE_NAME); + Object searchVal = parameter.get("searchVal"); + if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){ + WHERE( " queue like concat('%', #{searchVal}, '%') "); + } + }}.toString(); + } + + /** + * query tenant list paging + * @param parameter + * @return + */ + public String queryQueuePaging(Map parameter) { + return new SQL() { + { + SELECT("*"); + FROM(TABLE_NAME); + Object searchVal = parameter.get("searchVal"); + if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){ + WHERE( " queue like concat('%', #{searchVal}, '%') "); + } + ORDER_BY(" update_time desc limit #{offset},#{pageSize} "); + } + }.toString(); + + } + + /** + * query by queue + * + * @param parameter + * @return + */ + public String queryByQueue(Map parameter) { + return new SQL() { + { + SELECT("*"); + + FROM(TABLE_NAME); + + WHERE("`queue` = #{queue}"); + } + }.toString(); + } } From 6548195a0c590d8fad5fc7560be32d81ef2d37b2 Mon Sep 17 00:00:00 2001 From: ligang Date: Thu, 11 Apr 2019 16:33:05 +0800 Subject: [PATCH 04/15] update QueueController and QueueService --- .../api/controller/QueueController.java | 80 +++++++++++++- .../escheduler/api/service/QueueService.java | 103 ++++++++++++++++++ .../api/controller/QueueControllerTest.java | 60 ++++++++++ 3 files changed, 242 insertions(+), 1 deletion(-) diff --git a/escheduler-api/src/main/java/cn/escheduler/api/controller/QueueController.java b/escheduler-api/src/main/java/cn/escheduler/api/controller/QueueController.java index ac18b5c7c3..d34a9e0d30 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/controller/QueueController.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/controller/QueueController.java @@ -17,6 +17,7 @@ package cn.escheduler.api.controller; +import cn.escheduler.api.enums.Status; import cn.escheduler.api.service.QueueService; import cn.escheduler.api.utils.Constants; import cn.escheduler.api.utils.Result; @@ -29,7 +30,7 @@ import org.springframework.web.bind.annotation.*; import java.util.Map; -import static cn.escheduler.api.enums.Status.QUERY_QUEUE_LIST_ERROR; +import static cn.escheduler.api.enums.Status.*; /** @@ -63,5 +64,82 @@ public class QueueController extends BaseController{ } } + /** + * query queue list paging + * @param loginUser + * @return + */ + @GetMapping(value="/list-paging") + @ResponseStatus(HttpStatus.OK) + public Result queryQueueListPaging(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestParam("pageNo") Integer pageNo, + @RequestParam(value = "searchVal", required = false) String searchVal, + @RequestParam("pageSize") Integer pageSize){ + try{ + logger.info("login user {}, query queue list,search value:{}", loginUser.getUserName(),searchVal); + Map result = checkPageParams(pageNo, pageSize); + if(result.get(Constants.STATUS) != Status.SUCCESS){ + return returnDataListPaging(result); + } + + result = queueService.queryList(loginUser,searchVal,pageNo,pageSize); + return returnDataList(result); + }catch (Exception e){ + logger.error(QUERY_QUEUE_LIST_ERROR.getMsg(),e); + return error(QUERY_QUEUE_LIST_ERROR.getCode(), QUERY_QUEUE_LIST_ERROR.getMsg()); + } + } + + /** + * create queue + * + * @param loginUser + * @param queue + * @param queueName + * @return + */ + @PostMapping(value = "/create") + @ResponseStatus(HttpStatus.CREATED) + public Result createQueue(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestParam(value = "queue") String queue, + @RequestParam(value = "queueName") String queueName) { + logger.info("login user {}, create queue, queue: {}, queueName: {}", + loginUser.getUserName(), queue, queueName); + try { + Map result = queueService.createQueue(loginUser,queue,queueName); + return returnDataList(result); + + }catch (Exception e){ + logger.error(CREATE_QUEUE_ERROR.getMsg(),e); + return error(CREATE_QUEUE_ERROR.getCode(), CREATE_QUEUE_ERROR.getMsg()); + } + } + + /** + * update queue + * + * @param loginUser + * @param queue + * @param queueName + * @return + */ + @PostMapping(value = "/update") + @ResponseStatus(HttpStatus.CREATED) + public Result updateQueue(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestParam(value = "id") int id, + @RequestParam(value = "queue") String queue, + @RequestParam(value = "queueName") String queueName) { + logger.info("login user {}, update queue, id: {}, queue: {}, queueName: {}", + loginUser.getUserName(), id,queue, queueName); + try { + Map result = queueService.updateQueue(loginUser,id,queue,queueName); + return returnDataList(result); + + }catch (Exception e){ + logger.error(UPDATE_QUEUE_ERROR.getMsg(),e); + return error(UPDATE_QUEUE_ERROR.getCode(), UPDATE_QUEUE_ERROR.getMsg()); + } + } + } diff --git a/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java b/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java index 4f84cb7d67..222f2ee90e 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java @@ -18,12 +18,15 @@ 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.dao.mapper.QueueMapper; import cn.escheduler.dao.model.Queue; import cn.escheduler.dao.model.User; +import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -57,4 +60,104 @@ public class QueueService extends BaseService{ return result; } + /** + * query queue list paging + * @param loginUser + * @param searchVal + * @param pageNo + * @param pageSize + * @return + */ + public Map queryList(User loginUser,String searchVal, Integer pageNo, Integer pageSize) { + Map result = new HashMap<>(5); + if (checkAdmin(loginUser, result)) { + return result; + } + + Integer count = queueMapper.countQueuePaging(searchVal); + + PageInfo pageInfo = new PageInfo<>(pageNo,pageSize); + + List queueList = queueMapper.queryQueuePaging(searchVal,pageInfo.getStart(),pageSize); + + pageInfo.setTotalCount(count); + pageInfo.setLists(queueList); + result.put(Constants.DATA_LIST, queueList); + putMsg(result,Status.SUCCESS); + + return result; + } + + public Map createQueue(User loginUser,String queue, String queueName) { + Map result = new HashMap<>(5); + if (checkAdmin(loginUser, result)) { + return result; + } + + if (checkQueueExists(queue)){ + putMsg(result, Status.QUEUE_EXIST, queue); + return result; + } + + Queue queueObj = new Queue(); + Date now = new Date(); + + queueObj.setQueue(queue); + queueObj.setQueueName(queueName); + queueObj.setCreateTime(now); + queueObj.setUpdateTime(now); + + queueMapper.insert(queueObj); + putMsg(result, Status.SUCCESS); + + return result; + } + + public Map updateQueue(User loginUser,int id,String queue, String queueName) { + Map result = new HashMap<>(5); + if (checkAdmin(loginUser, result)) { + return result; + } + + + + Queue queueObj = queueMapper.queryById(id); + if (queueObj == null) { + putMsg(result,Status.QUEUE_NOT_EXIST,id); + return result; + } + + //update queue + + if (StringUtils.isNotEmpty(queue)) { + if (!queue.equals(queueObj.getQueue()) && checkQueueExists(queue)) { + putMsg(result, Status.QUEUE_EXIST, queue); + return result; + } + queueObj.setQueue(queue); + } + if (StringUtils.isNotEmpty(queueName)) { + queueObj.setQueueName(queueName); + } + Date now = new Date(); + + queueObj.setUpdateTime(now); + + queueMapper.update(queueObj); + putMsg(result, Status.SUCCESS); + + return result; + } + + + /** + * check queue exists + * + * @param queue + * @return + */ + private boolean checkQueueExists(String queue) { + return queueMapper.queryByQueue(queue) == null ? false : true; + } + } diff --git a/escheduler-api/src/test/java/cn/escheduler/api/controller/QueueControllerTest.java b/escheduler-api/src/test/java/cn/escheduler/api/controller/QueueControllerTest.java index 3943c6ce9a..f1ced425fe 100644 --- a/escheduler-api/src/test/java/cn/escheduler/api/controller/QueueControllerTest.java +++ b/escheduler-api/src/test/java/cn/escheduler/api/controller/QueueControllerTest.java @@ -32,9 +32,12 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.web.context.WebApplicationContext; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -65,4 +68,61 @@ public class QueueControllerTest { Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } + + @Test + public void queryPagingList() throws Exception { + + MultiValueMap paramsMap = new LinkedMultiValueMap<>(); + //paramsMap.add("processInstanceId","1380"); + paramsMap.add("searchVal",""); + paramsMap.add("pageNo","1"); + paramsMap.add("pageSize","20"); + + MvcResult mvcResult = mockMvc.perform(get("/queue/list-paging") + .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()); + } + + @Test + public void createQueue() throws Exception { + + MultiValueMap paramsMap = new LinkedMultiValueMap<>(); + paramsMap.add("queue","ait1111"); + paramsMap.add("queueName","aitName"); + + MvcResult mvcResult = mockMvc.perform(post("/queue/create") + .header("sessionId", "d4541e0d-0349-4f05-9c68-300176cd3c91") + .params(paramsMap)) + .andExpect(status().isCreated()) + .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()); + } + + @Test + public void updateQueue() throws Exception { + + MultiValueMap paramsMap = new LinkedMultiValueMap<>(); + paramsMap.add("id","2"); + paramsMap.add("queue","ait1"); + paramsMap.add("queueName","aitName"); + + MvcResult mvcResult = mockMvc.perform(post("/queue/update") + .header("sessionId", "d4541e0d-0349-4f05-9c68-300176cd3c91") + .params(paramsMap)) + .andExpect(status().isCreated()) + .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()); + } } \ No newline at end of file From a91c6b16aa4463c90a51ddbc9981e62bc6755aa8 Mon Sep 17 00:00:00 2001 From: ligang Date: Thu, 11 Apr 2019 17:02:28 +0800 Subject: [PATCH 05/15] update returnDataListPaging --- .../main/java/cn/escheduler/api/controller/QueueController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/escheduler-api/src/main/java/cn/escheduler/api/controller/QueueController.java b/escheduler-api/src/main/java/cn/escheduler/api/controller/QueueController.java index d34a9e0d30..debf29a524 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/controller/QueueController.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/controller/QueueController.java @@ -83,7 +83,7 @@ public class QueueController extends BaseController{ } result = queueService.queryList(loginUser,searchVal,pageNo,pageSize); - return returnDataList(result); + return returnDataListPaging(result); }catch (Exception e){ logger.error(QUERY_QUEUE_LIST_ERROR.getMsg(),e); return error(QUERY_QUEUE_LIST_ERROR.getCode(), QUERY_QUEUE_LIST_ERROR.getMsg()); From a11418a5889024607f29106e604bb3cd9cd97ef2 Mon Sep 17 00:00:00 2001 From: ligang Date: Thu, 11 Apr 2019 17:21:18 +0800 Subject: [PATCH 06/15] update QueueService --- .../src/main/java/cn/escheduler/api/service/QueueService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java b/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java index 222f2ee90e..621fd741e9 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java @@ -82,7 +82,7 @@ public class QueueService extends BaseService{ pageInfo.setTotalCount(count); pageInfo.setLists(queueList); - result.put(Constants.DATA_LIST, queueList); + result.put(Constants.DATA_LIST, pageInfo); putMsg(result,Status.SUCCESS); return result; From 30a63a05aa0fa69012143cf0ef868610e55d8c93 Mon Sep 17 00:00:00 2001 From: ligang Date: Thu, 11 Apr 2019 18:06:49 +0800 Subject: [PATCH 07/15] add verify queue_name --- .../java/cn/escheduler/api/enums/Status.java | 3 +- .../escheduler/api/service/QueueService.java | 240 ++++++++++-------- 2 files changed, 133 insertions(+), 110 deletions(-) diff --git a/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java b/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java index b99d3fa743..db050633cb 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java @@ -152,7 +152,8 @@ public enum Status { CREATE_QUEUE_ERROR(10127, "create queue error"), QUEUE_NOT_EXIST(10128, "queue {0} not exists"), QUEUE_EXIST(10129, "queue already exists"), - UPDATE_QUEUE_ERROR(10130, "update queue error"), + QUEUE_NAME_EXIST(10130, "queue name already exists"), + UPDATE_QUEUE_ERROR(10131, "update queue error"), UDF_FUNCTION_NOT_EXIST(20001, "UDF function not found"), diff --git a/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java b/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java index 621fd741e9..109719eb03 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java @@ -35,129 +35,151 @@ import java.util.Map; * queue service */ @Service -public class QueueService extends BaseService{ - - - @Autowired - private QueueMapper queueMapper; - - /** - * query queue list - * - * @param loginUser - * @return - */ - public Map queryList(User loginUser) { - Map result = new HashMap<>(5); - if (checkAdmin(loginUser, result)) { - return result; - } - - List queueList = queueMapper.queryAllQueue(); - result.put(Constants.DATA_LIST, queueList); - putMsg(result,Status.SUCCESS); - - return result; - } - - /** - * query queue list paging - * @param loginUser - * @param searchVal - * @param pageNo - * @param pageSize - * @return - */ - public Map queryList(User loginUser,String searchVal, Integer pageNo, Integer pageSize) { - Map result = new HashMap<>(5); - if (checkAdmin(loginUser, result)) { - return result; - } - - Integer count = queueMapper.countQueuePaging(searchVal); +public class QueueService extends BaseService { - PageInfo pageInfo = new PageInfo<>(pageNo,pageSize); - List queueList = queueMapper.queryQueuePaging(searchVal,pageInfo.getStart(),pageSize); + @Autowired + private QueueMapper queueMapper; - pageInfo.setTotalCount(count); - pageInfo.setLists(queueList); - result.put(Constants.DATA_LIST, pageInfo); - putMsg(result,Status.SUCCESS); + /** + * query queue list + * + * @param loginUser + * @return + */ + public Map queryList(User loginUser) { + Map result = new HashMap<>(5); + if (checkAdmin(loginUser, result)) { + return result; + } - return result; - } + List queueList = queueMapper.queryAllQueue(); + result.put(Constants.DATA_LIST, queueList); + putMsg(result, Status.SUCCESS); - public Map createQueue(User loginUser,String queue, String queueName) { - Map result = new HashMap<>(5); - if (checkAdmin(loginUser, result)) { - return result; + return result; } - if (checkQueueExists(queue)){ - putMsg(result, Status.QUEUE_EXIST, queue); - return result; + /** + * query queue list paging + * + * @param loginUser + * @param searchVal + * @param pageNo + * @param pageSize + * @return + */ + public Map queryList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { + Map result = new HashMap<>(5); + if (checkAdmin(loginUser, result)) { + return result; + } + + Integer count = queueMapper.countQueuePaging(searchVal); + + PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); + + List queueList = queueMapper.queryQueuePaging(searchVal, pageInfo.getStart(), pageSize); + + pageInfo.setTotalCount(count); + pageInfo.setLists(queueList); + result.put(Constants.DATA_LIST, pageInfo); + putMsg(result, Status.SUCCESS); + + return result; } - Queue queueObj = new Queue(); - Date now = new Date(); - - queueObj.setQueue(queue); - queueObj.setQueueName(queueName); - queueObj.setCreateTime(now); - queueObj.setUpdateTime(now); - - queueMapper.insert(queueObj); - putMsg(result, Status.SUCCESS); - - return result; - } - - public Map updateQueue(User loginUser,int id,String queue, String queueName) { - Map result = new HashMap<>(5); - if (checkAdmin(loginUser, result)) { - return result; + /** + * create queue + * + * @param loginUser + * @param queue + * @param queueName + * @return + */ + public Map createQueue(User loginUser, String queue, String queueName) { + Map result = new HashMap<>(5); + if (checkAdmin(loginUser, result)) { + return result; + } + + if (checkQueueExists(queue)) { + putMsg(result, Status.QUEUE_EXIST, queue); + return result; + } + + if (checkQueueExists(queueName)) { + putMsg(result, Status.QUEUE_NAME_EXIST, queueName); + return result; + } + + Queue queueObj = new Queue(); + Date now = new Date(); + + queueObj.setQueue(queue); + queueObj.setQueueName(queueName); + queueObj.setCreateTime(now); + queueObj.setUpdateTime(now); + + queueMapper.insert(queueObj); + putMsg(result, Status.SUCCESS); + + return result; } - - - Queue queueObj = queueMapper.queryById(id); - if (queueObj == null) { - putMsg(result,Status.QUEUE_NOT_EXIST,id); - return result; + /** + * update queue + * + * @param loginUser + * @param id + * @param queue + * @param queueName + * @return + */ + public Map updateQueue(User loginUser, int id, String queue, String queueName) { + Map result = new HashMap<>(5); + if (checkAdmin(loginUser, result)) { + return result; + } + + + Queue queueObj = queueMapper.queryById(id); + if (queueObj == null) { + putMsg(result, Status.QUEUE_NOT_EXIST, id); + return result; + } + + //update queue + + if (StringUtils.isNotEmpty(queue)) { + if (!queue.equals(queueObj.getQueue()) && checkQueueExists(queue)) { + putMsg(result, Status.QUEUE_EXIST, queue); + return result; + } + queueObj.setQueue(queue); + } + if (StringUtils.isNotEmpty(queueName)) { + queueObj.setQueueName(queueName); + } + Date now = new Date(); + + queueObj.setUpdateTime(now); + + queueMapper.update(queueObj); + putMsg(result, Status.SUCCESS); + + return result; } - //update queue - if (StringUtils.isNotEmpty(queue)) { - if (!queue.equals(queueObj.getQueue()) && checkQueueExists(queue)) { - putMsg(result, Status.QUEUE_EXIST, queue); - return result; - } - queueObj.setQueue(queue); + /** + * check queue exists + * + * @param queue + * @return + */ + private boolean checkQueueExists(String queue) { + return queueMapper.queryByQueue(queue) == null ? false : true; } - if (StringUtils.isNotEmpty(queueName)) { - queueObj.setQueueName(queueName); - } - Date now = new Date(); - - queueObj.setUpdateTime(now); - - queueMapper.update(queueObj); - putMsg(result, Status.SUCCESS); - - return result; - } - - - /** - * check queue exists - * - * @param queue - * @return - */ - private boolean checkQueueExists(String queue) { - return queueMapper.queryByQueue(queue) == null ? false : true; - } } From 4214d60ffa86c729601aeb35aae56f7f6bce17f2 Mon Sep 17 00:00:00 2001 From: ligang Date: Thu, 11 Apr 2019 18:39:54 +0800 Subject: [PATCH 08/15] add queryByQueueName --- .../cn/escheduler/dao/mapper/QueueMapper.java | 3 +++ .../dao/mapper/QueueMapperProvider.java | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapper.java b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapper.java index b5e8ad99be..c5ca32429c 100644 --- a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapper.java +++ b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapper.java @@ -112,5 +112,8 @@ public interface QueueMapper { @SelectProvider(type = QueueMapperProvider.class, method = "queryByQueue") Queue queryByQueue(@Param("queue") String queue); + @SelectProvider(type = QueueMapperProvider.class, method = "queryByQueueName") + Queue queryByQueueName(@Param("queueName") String queueName); + } diff --git a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapperProvider.java b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapperProvider.java index e3adbaa1e6..5afd45df9f 100644 --- a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapperProvider.java +++ b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapperProvider.java @@ -170,4 +170,22 @@ public class QueueMapperProvider { }.toString(); } + /** + * query by queue name + * + * @param parameter + * @return + */ + public String queryByQueueName(Map parameter) { + return new SQL() { + { + SELECT("*"); + + FROM(TABLE_NAME); + + WHERE("`queue_name` = #{queueName}"); + } + }.toString(); + } + } From 0b85a92e2c149bcdead1b58f4fe96d0db2eeafb8 Mon Sep 17 00:00:00 2001 From: ligang Date: Thu, 11 Apr 2019 18:42:13 +0800 Subject: [PATCH 09/15] add NEED_NOT_UPDATE_QUEUE and VERIFY_QUEUE_ERROR --- .../src/main/java/cn/escheduler/api/enums/Status.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java b/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java index db050633cb..cebd983c2b 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java @@ -154,6 +154,8 @@ public enum Status { QUEUE_EXIST(10129, "queue already exists"), QUEUE_NAME_EXIST(10130, "queue name already exists"), UPDATE_QUEUE_ERROR(10131, "update queue error"), + NEED_NOT_UPDATE_QUEUE(10132, "need not update queue"), + VERIFY_QUEUE_ERROR(10133,"verify queue error"), UDF_FUNCTION_NOT_EXIST(20001, "UDF function not found"), From 022b49b45d95e77a8451f070d1d88e3a80554e64 Mon Sep 17 00:00:00 2001 From: ligang Date: Thu, 11 Apr 2019 20:06:03 +0800 Subject: [PATCH 10/15] update QUEUE_EXIST and QUEUE_NAME_EXIST --- .../src/main/java/cn/escheduler/api/enums/Status.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java b/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java index cebd983c2b..284a75ed25 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java @@ -151,8 +151,8 @@ public enum Status { SCHEDULE_CRON_REALEASE_NEED_NOT_CHANGE(10126, "schedule release is already {0}"), CREATE_QUEUE_ERROR(10127, "create queue error"), QUEUE_NOT_EXIST(10128, "queue {0} not exists"), - QUEUE_EXIST(10129, "queue already exists"), - QUEUE_NAME_EXIST(10130, "queue name already exists"), + QUEUE_EXIST(10129, "queue {0} already exists"), + QUEUE_NAME_EXIST(10130, "queue name {0} already exists"), UPDATE_QUEUE_ERROR(10131, "update queue error"), NEED_NOT_UPDATE_QUEUE(10132, "need not update queue"), VERIFY_QUEUE_ERROR(10133,"verify queue error"), From 5d41d66427f84b705f205205cafb59236170b6a3 Mon Sep 17 00:00:00 2001 From: ligang Date: Thu, 11 Apr 2019 20:06:39 +0800 Subject: [PATCH 11/15] update QueueController and QueueService --- .../api/controller/QueueController.java | 25 +++++ .../escheduler/api/service/QueueService.java | 93 ++++++++++++++++--- .../api/controller/QueueControllerTest.java | 24 ++++- 3 files changed, 127 insertions(+), 15 deletions(-) diff --git a/escheduler-api/src/main/java/cn/escheduler/api/controller/QueueController.java b/escheduler-api/src/main/java/cn/escheduler/api/controller/QueueController.java index debf29a524..29c01a1483 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/controller/QueueController.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/controller/QueueController.java @@ -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()); + } + } + } diff --git a/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java b/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java index 109719eb03..a1cba1f13f 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java @@ -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); + + // check queueName is exist + if (!queueName.equals(queueObj.getQueueName())) { + if(checkQueueNameExist(queueName)){ + putMsg(result, Status.QUEUE_NAME_EXIST, queueName); + return result; + } } - Date now = new Date(); + // 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; + } + } diff --git a/escheduler-api/src/test/java/cn/escheduler/api/controller/QueueControllerTest.java b/escheduler-api/src/test/java/cn/escheduler/api/controller/QueueControllerTest.java index f1ced425fe..3ea445be66 100644 --- a/escheduler-api/src/test/java/cn/escheduler/api/controller/QueueControllerTest.java +++ b/escheduler-api/src/test/java/cn/escheduler/api/controller/QueueControllerTest.java @@ -93,8 +93,8 @@ public class QueueControllerTest { public void createQueue() throws Exception { MultiValueMap 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 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 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()); + } } \ No newline at end of file From 8394c9bfe59f2a24fcb326b1ea5d10e40ca5989d Mon Sep 17 00:00:00 2001 From: ligang Date: Thu, 11 Apr 2019 20:17:10 +0800 Subject: [PATCH 12/15] update countQueuePaging and queryQueuePaging --- .../java/cn/escheduler/dao/mapper/QueueMapperProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapperProvider.java b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapperProvider.java index 5afd45df9f..9ce6d187f3 100644 --- a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapperProvider.java +++ b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/QueueMapperProvider.java @@ -127,7 +127,7 @@ public class QueueMapperProvider { FROM(TABLE_NAME); Object searchVal = parameter.get("searchVal"); if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){ - WHERE( " queue like concat('%', #{searchVal}, '%') "); + WHERE( " queue_name like concat('%', #{searchVal}, '%') "); } }}.toString(); } @@ -144,7 +144,7 @@ public class QueueMapperProvider { FROM(TABLE_NAME); Object searchVal = parameter.get("searchVal"); if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){ - WHERE( " queue like concat('%', #{searchVal}, '%') "); + WHERE( " queue_name like concat('%', #{searchVal}, '%') "); } ORDER_BY(" update_time desc limit #{offset},#{pageSize} "); } From 68d0c974a7e39282e16c791e46cee5551e996370 Mon Sep 17 00:00:00 2001 From: ligang Date: Fri, 12 Apr 2019 11:22:04 +0800 Subject: [PATCH 13/15] update stauts and QueueService --- .../java/cn/escheduler/api/enums/Status.java | 4 +-- .../escheduler/api/service/QueueService.java | 32 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java b/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java index 284a75ed25..253e8edb52 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java @@ -151,10 +151,10 @@ public enum Status { SCHEDULE_CRON_REALEASE_NEED_NOT_CHANGE(10126, "schedule release is already {0}"), CREATE_QUEUE_ERROR(10127, "create queue error"), QUEUE_NOT_EXIST(10128, "queue {0} not exists"), - QUEUE_EXIST(10129, "queue {0} already exists"), + QUEUE_VALUE_EXIST(10129, "queue value {0} already exists"), QUEUE_NAME_EXIST(10130, "queue name {0} already exists"), UPDATE_QUEUE_ERROR(10131, "update queue error"), - NEED_NOT_UPDATE_QUEUE(10132, "need not update queue"), + NEED_NOT_UPDATE_QUEUE(10132, "no content changes, no updates are required"), VERIFY_QUEUE_ERROR(10133,"verify queue error"), diff --git a/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java b/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java index a1cba1f13f..24bd6cfc97 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java @@ -117,13 +117,13 @@ public class QueueService extends BaseService { return result; } - if (checkQueueExist(queue)) { - putMsg(result, Status.QUEUE_EXIST, queue); + if (checkQueueNameExist(queueName)) { + putMsg(result, Status.QUEUE_NAME_EXIST, queueName); return result; } - if (checkQueueNameExist(queueName)) { - putMsg(result, Status.QUEUE_NAME_EXIST, queueName); + if (checkQueueExist(queue)) { + putMsg(result, Status.QUEUE_VALUE_EXIST, queue); return result; } @@ -162,24 +162,24 @@ public class QueueService extends BaseService { return result; } - // whether queue and queueName is changed + // whether queue value or queueName is changed if (queue.equals(queueObj.getQueue()) && queueName.equals(queueObj.getQueueName())) { putMsg(result, Status.NEED_NOT_UPDATE_QUEUE); return result; } - // check queue is exist - if (!queue.equals(queueObj.getQueue())) { - if(checkQueueExist(queue)){ - putMsg(result, Status.QUEUE_EXIST, queue); + // check queue name is exist + if (!queueName.equals(queueObj.getQueueName())) { + if(checkQueueNameExist(queueName)){ + putMsg(result, Status.QUEUE_NAME_EXIST, queueName); return result; } } - // check queueName is exist - if (!queueName.equals(queueObj.getQueueName())) { - if(checkQueueNameExist(queueName)){ - putMsg(result, Status.QUEUE_NAME_EXIST, queueName); + // check queue value is exist + if (!queue.equals(queueObj.getQueue())) { + if(checkQueueExist(queue)){ + putMsg(result, Status.QUEUE_VALUE_EXIST, queue); return result; } } @@ -216,13 +216,13 @@ public class QueueService extends BaseService { return result; } if(checkQueueExist(queue)){ - logger.error("queue {} has exist, can't create again.", queue); - putMsg(result, Status.QUEUE_EXIST, queue); + logger.error("queue value {} has exist, can't create again.", queue); + putMsg(result, Status.QUEUE_VALUE_EXIST, queue); return result; } if(checkQueueNameExist(queueName)){ - logger.error("queueName {} has exist, can't create again.", queueName); + logger.error("queue name {} has exist, can't create again.", queueName); putMsg(result, Status.QUEUE_NAME_EXIST, queueName); return result; } From 15ebd9d41f86506534fdff3a306c45077d955ea1 Mon Sep 17 00:00:00 2001 From: ligang Date: Fri, 12 Apr 2019 11:32:22 +0800 Subject: [PATCH 14/15] update verifyQueue --- .../java/cn/escheduler/api/service/QueueService.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java b/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java index 24bd6cfc97..45f574ed49 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/service/QueueService.java @@ -215,11 +215,7 @@ public class QueueService extends BaseService { putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, queueName); return result; } - if(checkQueueExist(queue)){ - logger.error("queue value {} has exist, can't create again.", queue); - putMsg(result, Status.QUEUE_VALUE_EXIST, queue); - return result; - } + if(checkQueueNameExist(queueName)){ logger.error("queue name {} has exist, can't create again.", queueName); @@ -227,6 +223,12 @@ public class QueueService extends BaseService { return result; } + if(checkQueueExist(queue)){ + logger.error("queue value {} has exist, can't create again.", queue); + putMsg(result, Status.QUEUE_VALUE_EXIST, queue); + return result; + } + putMsg(result, Status.SUCCESS); return result; } From 351c1e22467b19ab6043ae93b5a0d61f24db6d3e Mon Sep 17 00:00:00 2001 From: ligang Date: Fri, 12 Apr 2019 17:39:26 +0800 Subject: [PATCH 15/15] add escheduler_ddl.sql --- .../1.0.1_schema/mysql/escheduler_ddl.sql | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 sql/upgrade/1.0.1_schema/mysql/escheduler_ddl.sql diff --git a/sql/upgrade/1.0.1_schema/mysql/escheduler_ddl.sql b/sql/upgrade/1.0.1_schema/mysql/escheduler_ddl.sql new file mode 100644 index 0000000000..40a8d48077 --- /dev/null +++ b/sql/upgrade/1.0.1_schema/mysql/escheduler_ddl.sql @@ -0,0 +1,41 @@ +SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); +-- ac_escheduler_T_t_escheduler_queue_C_create_time +drop PROCEDURE if EXISTS ac_escheduler_T_t_escheduler_queue_C_create_time; +delimiter d// +CREATE PROCEDURE ac_escheduler_T_t_escheduler_queue_C_create_time() + BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_NAME='t_escheduler_queue' + AND TABLE_SCHEMA='escheduler' + AND COLUMN_NAME='create_time') + THEN + ALTER TABLE escheduler.t_escheduler_queue ADD COLUMN create_time datetime DEFAULT NULL COMMENT '创建时间' AFTER queue; + END IF; + END; + +d// + +delimiter ; +CALL ac_escheduler_T_t_escheduler_queue_C_create_time; +DROP PROCEDURE ac_escheduler_T_t_escheduler_queue_C_create_time; + + +-- ac_escheduler_T_t_escheduler_queue_C_update_time +drop PROCEDURE if EXISTS ac_escheduler_T_t_escheduler_queue_C_update_time; +delimiter d// +CREATE PROCEDURE ac_escheduler_T_t_escheduler_queue_C_update_time() + BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_NAME='t_escheduler_queue' + AND TABLE_SCHEMA='escheduler' + AND COLUMN_NAME='update_time') + THEN + ALTER TABLE escheduler.t_escheduler_queue ADD COLUMN update_time datetime DEFAULT NULL COMMENT '更新时间' AFTER create_time; + END IF; + END; + +d// + +delimiter ; +CALL ac_escheduler_T_t_escheduler_queue_C_update_time; +DROP PROCEDURE ac_escheduler_T_t_escheduler_queue_C_update_time; \ No newline at end of file