bao liang
6 years ago
committed by
GitHub
36 changed files with 1037 additions and 43 deletions
@ -0,0 +1,144 @@ |
|||||||
|
/* |
||||||
|
* 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 cn.escheduler.api.controller; |
||||||
|
|
||||||
|
|
||||||
|
import cn.escheduler.api.enums.Status; |
||||||
|
import cn.escheduler.api.service.WorkerGroupService; |
||||||
|
import cn.escheduler.api.utils.Constants; |
||||||
|
import cn.escheduler.api.utils.Result; |
||||||
|
import cn.escheduler.dao.model.User; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.http.HttpStatus; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* worker group controller |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/worker-group") |
||||||
|
public class WorkerGroupController extends BaseController{ |
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(WorkerGroupController.class); |
||||||
|
|
||||||
|
|
||||||
|
@Autowired |
||||||
|
WorkerGroupService workerGroupService; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* create or update a worker group |
||||||
|
* @param loginUser |
||||||
|
* @param id |
||||||
|
* @param name |
||||||
|
* @param ipList |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@PostMapping(value = "/save") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
public Result saveWorkerGroup(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam(value = "id", required = false, defaultValue = "0") int id, |
||||||
|
@RequestParam(value = "name") String name, |
||||||
|
@RequestParam(value = "ipList") String ipList |
||||||
|
) { |
||||||
|
logger.info("save worker group: login user {}, id:{}, name: {}, ipList: {} ", |
||||||
|
loginUser.getUserName(), id, name, ipList); |
||||||
|
|
||||||
|
try { |
||||||
|
Map<String, Object> result = workerGroupService.saveWorkerGroup(id, name, ipList); |
||||||
|
return returnDataList(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(Status.SAVE_ERROR.getMsg(),e); |
||||||
|
return error(Status.SAVE_ERROR.getCode(), Status.SAVE_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query worker groups paging |
||||||
|
* @param loginUser |
||||||
|
* @param pageNo |
||||||
|
* @param searchVal |
||||||
|
* @param pageSize |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@GetMapping(value = "/list-paging") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
public Result queryAllWorkerGroupsPaging(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam("pageNo") Integer pageNo, |
||||||
|
@RequestParam(value = "searchVal", required = false) String searchVal, |
||||||
|
@RequestParam("pageSize") Integer pageSize |
||||||
|
) { |
||||||
|
logger.info("query all worker group paging: login user {}, pageNo:{}, pageSize:{}, searchVal:{}", |
||||||
|
loginUser.getUserName() , pageNo, pageSize, searchVal); |
||||||
|
|
||||||
|
try { |
||||||
|
Map<String, Object> result = workerGroupService.queryAllGroupPaging(pageNo, pageSize, searchVal); |
||||||
|
return returnDataListPaging(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(Status.SAVE_ERROR.getMsg(),e); |
||||||
|
return error(Status.SAVE_ERROR.getCode(), Status.SAVE_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query all worker groups |
||||||
|
* @param loginUser |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@GetMapping(value = "/all-groups") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
public Result queryAllWorkerGroups(@RequestAttribute(value = Constants.SESSION_USER) User loginUser |
||||||
|
) { |
||||||
|
logger.info("query all worker group: login user {}", |
||||||
|
loginUser.getUserName() ); |
||||||
|
|
||||||
|
try { |
||||||
|
Map<String, Object> result = workerGroupService.queryAllGroup(); |
||||||
|
return returnDataList(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(Status.SAVE_ERROR.getMsg(),e); |
||||||
|
return error(Status.SAVE_ERROR.getCode(), Status.SAVE_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete worker group by id |
||||||
|
* @param loginUser |
||||||
|
* @param id |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@GetMapping(value = "/delete-by-id") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
public Result deleteById(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam("id") Integer id |
||||||
|
) { |
||||||
|
logger.info("delete worker group: login user {}, id:{} ", |
||||||
|
loginUser.getUserName() , id); |
||||||
|
|
||||||
|
try { |
||||||
|
Map<String, Object> result = workerGroupService.deleteWorkerGroupById(id); |
||||||
|
return returnDataList(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(Status.SAVE_ERROR.getMsg(),e); |
||||||
|
return error(Status.SAVE_ERROR.getCode(), Status.SAVE_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,155 @@ |
|||||||
|
/* |
||||||
|
* 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 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.WorkerGroupMapper; |
||||||
|
import cn.escheduler.dao.model.User; |
||||||
|
import cn.escheduler.dao.model.WorkerGroup; |
||||||
|
import org.apache.commons.lang3.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; |
||||||
|
|
||||||
|
/** |
||||||
|
* work group service |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class WorkerGroupService extends BaseService { |
||||||
|
|
||||||
|
|
||||||
|
@Autowired |
||||||
|
WorkerGroupMapper workerGroupMapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* create or update a worker group |
||||||
|
* @param id |
||||||
|
* @param name |
||||||
|
* @param ipList |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Map<String, Object> saveWorkerGroup(int id, String name, String ipList){ |
||||||
|
|
||||||
|
Map<String, Object> result = new HashMap<>(5); |
||||||
|
|
||||||
|
if(StringUtils.isEmpty(name)){ |
||||||
|
putMsg(result, Status.NAME_NULL); |
||||||
|
return result; |
||||||
|
} |
||||||
|
Date now = new Date(); |
||||||
|
WorkerGroup workerGroup = null; |
||||||
|
if(id != 0){ |
||||||
|
workerGroup = workerGroupMapper.queryById(id); |
||||||
|
}else{ |
||||||
|
workerGroup = new WorkerGroup(); |
||||||
|
workerGroup.setCreateTime(now); |
||||||
|
} |
||||||
|
workerGroup.setName(name); |
||||||
|
workerGroup.setIpList(ipList); |
||||||
|
workerGroup.setUpdateTime(now); |
||||||
|
|
||||||
|
if(checkWorkerGroupNameExists(workerGroup)){ |
||||||
|
putMsg(result, Status.NAME_EXIST, workerGroup.getName()); |
||||||
|
return result; |
||||||
|
} |
||||||
|
if(workerGroup.getId() != 0 ){ |
||||||
|
workerGroupMapper.update(workerGroup); |
||||||
|
}else{ |
||||||
|
workerGroupMapper.insert(workerGroup); |
||||||
|
} |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* check worker group name exists |
||||||
|
* @param workerGroup |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private boolean checkWorkerGroupNameExists(WorkerGroup workerGroup) { |
||||||
|
|
||||||
|
List<WorkerGroup> workerGroupList = workerGroupMapper.queryWorkerGroupByName(workerGroup.getName()); |
||||||
|
|
||||||
|
if(workerGroupList.size() > 0 ){ |
||||||
|
// new group has same name..
|
||||||
|
if(workerGroup.getId() == 0){ |
||||||
|
return true; |
||||||
|
} |
||||||
|
// update group...
|
||||||
|
for(WorkerGroup group : workerGroupList){ |
||||||
|
if(group.getId() != workerGroup.getId()){ |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query worker group paging |
||||||
|
* @param pageNo |
||||||
|
* @param pageSize |
||||||
|
* @param searchVal |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Map<String,Object> queryAllGroupPaging(Integer pageNo, Integer pageSize, String searchVal) { |
||||||
|
|
||||||
|
Map<String, Object> result = new HashMap<>(5); |
||||||
|
int count = workerGroupMapper.countPaging(searchVal); |
||||||
|
|
||||||
|
|
||||||
|
PageInfo<WorkerGroup> pageInfo = new PageInfo<>(pageNo, pageSize); |
||||||
|
List<WorkerGroup> workerGroupList = workerGroupMapper.queryListPaging(pageInfo.getStart(), pageSize, searchVal); |
||||||
|
pageInfo.setTotalCount(count); |
||||||
|
pageInfo.setLists(workerGroupList); |
||||||
|
result.put(Constants.DATA_LIST, pageInfo); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete worker group by id |
||||||
|
* @param id |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Map<String,Object> deleteWorkerGroupById(Integer id) { |
||||||
|
|
||||||
|
Map<String, Object> result = new HashMap<>(5); |
||||||
|
|
||||||
|
int delete = workerGroupMapper.deleteById(id); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query all worker group |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Map<String,Object> queryAllGroup() { |
||||||
|
Map<String, Object> result = new HashMap<>(5); |
||||||
|
List<WorkerGroup> workerGroupList = workerGroupMapper.queryAllWorkerGroup(); |
||||||
|
result.put(Constants.DATA_LIST, workerGroupList); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,131 @@ |
|||||||
|
/* |
||||||
|
* 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 cn.escheduler.dao.mapper; |
||||||
|
|
||||||
|
import cn.escheduler.dao.model.WorkerGroup; |
||||||
|
import org.apache.ibatis.annotations.*; |
||||||
|
import org.apache.ibatis.type.JdbcType; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* worker group mapper |
||||||
|
*/ |
||||||
|
public interface WorkerGroupMapper { |
||||||
|
|
||||||
|
/** |
||||||
|
* query all worker group list |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Results(value = { |
||||||
|
@Result(property = "id", column = "id", javaType = Integer.class, jdbcType = JdbcType.INTEGER), |
||||||
|
@Result(property = "ipList", column = "ip_list", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "createTime", column = "create_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), |
||||||
|
@Result(property = "updateTime", column = "update_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), |
||||||
|
}) |
||||||
|
@SelectProvider(type = WorkerGroupMapperProvider.class, method = "queryAllWorkerGroup") |
||||||
|
List<WorkerGroup> queryAllWorkerGroup(); |
||||||
|
|
||||||
|
/** |
||||||
|
* query worker group by name |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Results(value = { |
||||||
|
@Result(property = "id", column = "id", javaType = Integer.class, jdbcType = JdbcType.INTEGER), |
||||||
|
@Result(property = "ipList", column = "ip_list", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "createTime", column = "create_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), |
||||||
|
@Result(property = "updateTime", column = "update_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), |
||||||
|
}) |
||||||
|
@SelectProvider(type = WorkerGroupMapperProvider.class, method = "queryWorkerGroupByName") |
||||||
|
List<WorkerGroup> queryWorkerGroupByName(@Param("name") String name); |
||||||
|
|
||||||
|
/** |
||||||
|
* query worker group paging by search value |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Results(value = { |
||||||
|
@Result(property = "id", column = "id", javaType = Integer.class, jdbcType = JdbcType.INTEGER), |
||||||
|
@Result(property = "ipList", column = "ip_list", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "createTime", column = "create_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), |
||||||
|
@Result(property = "updateTime", column = "update_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), |
||||||
|
}) |
||||||
|
@SelectProvider(type = WorkerGroupMapperProvider.class, method = "queryListPaging") |
||||||
|
List<WorkerGroup> queryListPaging(@Param("offset") int offset, |
||||||
|
@Param("pageSize") int pageSize, |
||||||
|
@Param("searchVal") String searchVal); |
||||||
|
|
||||||
|
/** |
||||||
|
* count worker group by search value |
||||||
|
* @param searchVal |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@SelectProvider(type = WorkerGroupMapperProvider.class, method = "countPaging") |
||||||
|
int countPaging(@Param("searchVal") String searchVal); |
||||||
|
|
||||||
|
/** |
||||||
|
* insert worker server |
||||||
|
* |
||||||
|
* @param workerGroup |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@InsertProvider(type = WorkerGroupMapperProvider.class, method = "insert") |
||||||
|
@Options(useGeneratedKeys = true,keyProperty = "workerGroup.id") |
||||||
|
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "workerGroup.id", before = false, resultType = int.class) |
||||||
|
int insert(@Param("workerGroup") WorkerGroup workerGroup); |
||||||
|
|
||||||
|
/** |
||||||
|
* update worker |
||||||
|
* |
||||||
|
* @param workerGroup |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@UpdateProvider(type = WorkerGroupMapperProvider.class, method = "update") |
||||||
|
int update(@Param("workerGroup") WorkerGroup workerGroup); |
||||||
|
|
||||||
|
/** |
||||||
|
* delete work group by id |
||||||
|
* @param id |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@DeleteProvider(type = WorkerGroupMapperProvider.class, method = "deleteById") |
||||||
|
int deleteById(@Param("id") int id); |
||||||
|
|
||||||
|
/** |
||||||
|
* query work group by id |
||||||
|
* @param id |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Results(value = { |
||||||
|
@Result(property = "id", column = "id", javaType = Integer.class, jdbcType = JdbcType.INTEGER), |
||||||
|
@Result(property = "ipList", column = "ip_list", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "createTime", column = "create_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), |
||||||
|
@Result(property = "updateTime", column = "update_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), |
||||||
|
}) |
||||||
|
@SelectProvider(type = WorkerGroupMapperProvider.class, method = "queryById") |
||||||
|
WorkerGroup queryById(@Param("id") int id); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,160 @@ |
|||||||
|
/* |
||||||
|
* 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 cn.escheduler.dao.mapper; |
||||||
|
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
import org.apache.ibatis.jdbc.SQL; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* worker group mapper provider |
||||||
|
*/ |
||||||
|
public class WorkerGroupMapperProvider { |
||||||
|
|
||||||
|
private static final String TABLE_NAME = "t_escheduler_worker_group"; |
||||||
|
|
||||||
|
/** |
||||||
|
* query worker list |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String queryAllWorkerGroup() { |
||||||
|
return new SQL() {{ |
||||||
|
SELECT("*"); |
||||||
|
|
||||||
|
FROM(TABLE_NAME); |
||||||
|
|
||||||
|
ORDER_BY("update_time desc"); |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* insert worker server |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String insert(Map<String, Object> parameter) { |
||||||
|
return new SQL() {{ |
||||||
|
INSERT_INTO(TABLE_NAME); |
||||||
|
|
||||||
|
VALUES("id", "#{workerGroup.id}"); |
||||||
|
VALUES("name", "#{workerGroup.name}"); |
||||||
|
VALUES("ip_list", "#{workerGroup.ipList}"); |
||||||
|
VALUES("create_time", "#{workerGroup.createTime}"); |
||||||
|
VALUES("update_time", "#{workerGroup.updateTime}"); |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* update worker group |
||||||
|
* |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String update(Map<String, Object> parameter) { |
||||||
|
return new SQL() {{ |
||||||
|
UPDATE(TABLE_NAME); |
||||||
|
|
||||||
|
SET("name = #{workerGroup.name}"); |
||||||
|
SET("ip_list = #{workerGroup.ipList}"); |
||||||
|
SET("create_time = #{workerGroup.createTime}"); |
||||||
|
SET("update_time = #{workerGroup.updateTime}"); |
||||||
|
|
||||||
|
WHERE("id = #{workerGroup.id}"); |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete worker group by id |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String deleteById(Map<String, Object> parameter) { |
||||||
|
return new SQL() {{ |
||||||
|
DELETE_FROM(TABLE_NAME); |
||||||
|
|
||||||
|
WHERE("id = #{id}"); |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query worker group by name |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String queryWorkerGroupByName(Map<String, Object> parameter) { |
||||||
|
return new SQL() {{ |
||||||
|
|
||||||
|
SELECT("*"); |
||||||
|
FROM(TABLE_NAME); |
||||||
|
|
||||||
|
WHERE("name = #{name}"); |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query worker group by id |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String queryById(Map<String, Object> parameter) { |
||||||
|
return new SQL() {{ |
||||||
|
|
||||||
|
SELECT("*"); |
||||||
|
FROM(TABLE_NAME); |
||||||
|
|
||||||
|
WHERE("id = #{id}"); |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* query worker group by id |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String queryListPaging(Map<String, Object> parameter) { |
||||||
|
return new SQL() {{ |
||||||
|
|
||||||
|
SELECT("*"); |
||||||
|
FROM(TABLE_NAME); |
||||||
|
|
||||||
|
Object searchVal = parameter.get("searchVal"); |
||||||
|
if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){ |
||||||
|
WHERE( " name like concat('%', #{searchVal}, '%') "); |
||||||
|
} |
||||||
|
ORDER_BY(" update_time desc limit #{offset},#{pageSize} "); |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* count worker group number by search value |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String countPaging(Map<String, Object> parameter) { |
||||||
|
return new SQL() {{ |
||||||
|
SELECT("count(0)"); |
||||||
|
FROM(TABLE_NAME); |
||||||
|
Object searchVal = parameter.get("searchVal"); |
||||||
|
if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){ |
||||||
|
WHERE( " name like concat('%', #{searchVal}, '%') "); |
||||||
|
} |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,88 @@ |
|||||||
|
/* |
||||||
|
* 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 cn.escheduler.dao.model; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* worker group for task running |
||||||
|
*/ |
||||||
|
public class WorkerGroup { |
||||||
|
|
||||||
|
private int id; |
||||||
|
|
||||||
|
private String name; |
||||||
|
|
||||||
|
private String ipList; |
||||||
|
|
||||||
|
private Date createTime; |
||||||
|
|
||||||
|
private Date updateTime; |
||||||
|
|
||||||
|
|
||||||
|
public int getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
public void setId(int id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
public String getIpList() { |
||||||
|
return ipList; |
||||||
|
} |
||||||
|
|
||||||
|
public void setIpList(String ipList) { |
||||||
|
this.ipList = ipList; |
||||||
|
} |
||||||
|
|
||||||
|
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 "Worker group model{" + |
||||||
|
"id= " + id + |
||||||
|
",name= " + name + |
||||||
|
",ipList= " + ipList + |
||||||
|
",createTime= " + createTime + |
||||||
|
",updateTime= " + updateTime + |
||||||
|
|
||||||
|
"}"; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,69 @@ |
|||||||
|
/* |
||||||
|
* 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 cn.escheduler.dao.mapper; |
||||||
|
|
||||||
|
import cn.escheduler.dao.datasource.ConnectionFactory; |
||||||
|
import cn.escheduler.dao.model.WorkerGroup; |
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* worker group mapper test |
||||||
|
*/ |
||||||
|
public class WorkerGroupMapperTest { |
||||||
|
|
||||||
|
WorkerGroupMapper workerGroupMapper; |
||||||
|
|
||||||
|
|
||||||
|
@Before |
||||||
|
public void before() { |
||||||
|
workerGroupMapper = ConnectionFactory.getSqlSession().getMapper(WorkerGroupMapper.class); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Test |
||||||
|
public void test() { |
||||||
|
WorkerGroup workerGroup = new WorkerGroup(); |
||||||
|
|
||||||
|
String name = "workerGroup3"; |
||||||
|
workerGroup.setName(name); |
||||||
|
workerGroup.setIpList("192.168.220.154,192.168.220.188"); |
||||||
|
workerGroup.setCreateTime(new Date()); |
||||||
|
workerGroup.setUpdateTime(new Date()); |
||||||
|
workerGroupMapper.insert(workerGroup); |
||||||
|
Assert.assertNotEquals(workerGroup.getId(), 0); |
||||||
|
|
||||||
|
List<WorkerGroup> workerGroups2 = workerGroupMapper.queryWorkerGroupByName(name); |
||||||
|
Assert.assertEquals(workerGroups2.size(), 1); |
||||||
|
|
||||||
|
workerGroup.setName("workerGroup11"); |
||||||
|
workerGroupMapper.update(workerGroup); |
||||||
|
|
||||||
|
List<WorkerGroup> workerGroups = workerGroupMapper.queryAllWorkerGroup(); |
||||||
|
Assert.assertNotEquals(workerGroups.size(), 0); |
||||||
|
|
||||||
|
workerGroupMapper.deleteById(workerGroup.getId()); |
||||||
|
|
||||||
|
workerGroups = workerGroupMapper.queryAllWorkerGroup(); |
||||||
|
Assert.assertEquals(workerGroups.size(), 0); |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue