Browse Source
# Conflicts: # escheduler-api/src/main/java/cn/escheduler/api/enums/Status.javapull/2/head
dailidong
6 years ago
270 changed files with 11612 additions and 3888 deletions
@ -0,0 +1,169 @@
|
||||
/* |
||||
* 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.AccessTokenService; |
||||
import cn.escheduler.api.service.UsersService; |
||||
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; |
||||
|
||||
import static cn.escheduler.api.enums.Status.*; |
||||
|
||||
|
||||
/** |
||||
* user controller |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/access-token") |
||||
public class AccessTokenController extends BaseController{ |
||||
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AccessTokenController.class); |
||||
|
||||
|
||||
@Autowired |
||||
private AccessTokenService accessTokenService; |
||||
|
||||
/** |
||||
* create token |
||||
* @param loginUser |
||||
* @return |
||||
*/ |
||||
@PostMapping(value = "/create") |
||||
@ResponseStatus(HttpStatus.CREATED) |
||||
public Result createToken(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@RequestParam(value = "userId") int userId, |
||||
@RequestParam(value = "expireTime") String expireTime, |
||||
@RequestParam(value = "token") String token){ |
||||
logger.info("login user {}, create token , userId : {} , token expire time : {} , token : {}", loginUser.getUserName(), |
||||
userId,expireTime,token); |
||||
|
||||
try { |
||||
Map<String, Object> result = accessTokenService.createToken(userId, expireTime, token); |
||||
return returnDataList(result); |
||||
}catch (Exception e){ |
||||
logger.error(CREATE_ACCESS_TOKEN_ERROR.getMsg(),e); |
||||
return error(CREATE_ACCESS_TOKEN_ERROR.getCode(), CREATE_ACCESS_TOKEN_ERROR.getMsg()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* create token |
||||
* @param loginUser |
||||
* @return |
||||
*/ |
||||
@PostMapping(value = "/generate") |
||||
@ResponseStatus(HttpStatus.CREATED) |
||||
public Result generateToken(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@RequestParam(value = "userId") int userId, |
||||
@RequestParam(value = "expireTime") String expireTime){ |
||||
logger.info("login user {}, generate token , userId : {} , token expire time : {}",loginUser,userId,expireTime); |
||||
try { |
||||
Map<String, Object> result = accessTokenService.generateToken(userId, expireTime); |
||||
return returnDataList(result); |
||||
}catch (Exception e){ |
||||
logger.error(GENERATE_TOKEN_ERROR.getMsg(),e); |
||||
return error(GENERATE_TOKEN_ERROR.getCode(), GENERATE_TOKEN_ERROR.getMsg()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* query access token list paging |
||||
* |
||||
* @param loginUser |
||||
* @param pageNo |
||||
* @param searchVal |
||||
* @param pageSize |
||||
* @return |
||||
*/ |
||||
@GetMapping(value="/list-paging") |
||||
@ResponseStatus(HttpStatus.OK) |
||||
public Result queryAccessTokenList(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@RequestParam("pageNo") Integer pageNo, |
||||
@RequestParam(value = "searchVal", required = false) String searchVal, |
||||
@RequestParam("pageSize") Integer pageSize){ |
||||
logger.info("login user {}, list access token paging, pageNo: {}, searchVal: {}, pageSize: {}", |
||||
loginUser.getUserName(),pageNo,searchVal,pageSize); |
||||
try{ |
||||
Map<String, Object> result = checkPageParams(pageNo, pageSize); |
||||
if(result.get(Constants.STATUS) != Status.SUCCESS){ |
||||
return returnDataListPaging(result); |
||||
} |
||||
result = accessTokenService.queryAccessTokenList(loginUser, searchVal, pageNo, pageSize); |
||||
return returnDataListPaging(result); |
||||
}catch (Exception e){ |
||||
logger.error(QUERY_ACCESSTOKEN_LIST_PAGING_ERROR.getMsg(),e); |
||||
return error(QUERY_ACCESSTOKEN_LIST_PAGING_ERROR.getCode(),QUERY_ACCESSTOKEN_LIST_PAGING_ERROR.getMsg()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* delete access token by id |
||||
* @param loginUser |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
@PostMapping(value = "/delete") |
||||
@ResponseStatus(HttpStatus.OK) |
||||
public Result delAccessTokenById(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@RequestParam(value = "id") int id) { |
||||
logger.info("login user {}, delete access token, id: {},", loginUser.getUserName(), id); |
||||
try { |
||||
Map<String, Object> result = accessTokenService.delAccessTokenById(loginUser, id); |
||||
return returnDataList(result); |
||||
}catch (Exception e){ |
||||
logger.error(DELETE_USER_BY_ID_ERROR.getMsg(),e); |
||||
return error(Status.DELETE_USER_BY_ID_ERROR.getCode(), Status.DELETE_USER_BY_ID_ERROR.getMsg()); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* update token |
||||
* @param loginUser |
||||
* @return |
||||
*/ |
||||
@PostMapping(value = "/update") |
||||
@ResponseStatus(HttpStatus.CREATED) |
||||
public Result updateToken(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@RequestParam(value = "id") int id, |
||||
@RequestParam(value = "userId") int userId, |
||||
@RequestParam(value = "expireTime") String expireTime, |
||||
@RequestParam(value = "token") String token){ |
||||
logger.info("login user {}, update token , userId : {} , token expire time : {} , token : {}", loginUser.getUserName(), |
||||
userId,expireTime,token); |
||||
|
||||
try { |
||||
Map<String, Object> result = accessTokenService.updateToken(id,userId, expireTime, token); |
||||
return returnDataList(result); |
||||
}catch (Exception e){ |
||||
logger.error(CREATE_ACCESS_TOKEN_ERROR.getMsg(),e); |
||||
return error(CREATE_ACCESS_TOKEN_ERROR.getCode(), CREATE_ACCESS_TOKEN_ERROR.getMsg()); |
||||
} |
||||
} |
||||
|
||||
} |
@ -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,60 @@
|
||||
/* |
||||
* 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.dto; |
||||
|
||||
import cn.escheduler.common.enums.ExecutionStatus; |
||||
|
||||
/** |
||||
* command state count |
||||
*/ |
||||
public class CommandStateCount { |
||||
|
||||
private int errorCount; |
||||
private int normalCount; |
||||
private ExecutionStatus commandState; |
||||
|
||||
public CommandStateCount(){} |
||||
public CommandStateCount(int errorCount, int normalCount, ExecutionStatus commandState) { |
||||
this.errorCount = errorCount; |
||||
this.normalCount = normalCount; |
||||
this.commandState = commandState; |
||||
} |
||||
|
||||
public int getErrorCount() { |
||||
return errorCount; |
||||
} |
||||
|
||||
public void setErrorCount(int errorCount) { |
||||
this.errorCount = errorCount; |
||||
} |
||||
|
||||
public int getNormalCount() { |
||||
return normalCount; |
||||
} |
||||
|
||||
public void setNormalCount(int normalCount) { |
||||
this.normalCount = normalCount; |
||||
} |
||||
|
||||
public ExecutionStatus getCommandState() { |
||||
return commandState; |
||||
} |
||||
|
||||
public void setCommandState(ExecutionStatus commandState) { |
||||
this.commandState = commandState; |
||||
} |
||||
} |
@ -0,0 +1,185 @@
|
||||
/* |
||||
* 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.CheckUtils; |
||||
import cn.escheduler.api.utils.Constants; |
||||
import cn.escheduler.api.utils.PageInfo; |
||||
import cn.escheduler.api.utils.Result; |
||||
import cn.escheduler.common.enums.UserType; |
||||
import cn.escheduler.common.utils.*; |
||||
import cn.escheduler.dao.mapper.*; |
||||
import cn.escheduler.dao.model.*; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import java.util.*; |
||||
|
||||
/** |
||||
* user service |
||||
*/ |
||||
@Service |
||||
public class AccessTokenService extends BaseService { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AccessTokenService.class); |
||||
|
||||
@Autowired |
||||
private AccessTokenMapper accessTokenMapper; |
||||
|
||||
|
||||
/** |
||||
* query access token list |
||||
* |
||||
* @param loginUser |
||||
* @param searchVal |
||||
* @param pageNo |
||||
* @param pageSize |
||||
* @return |
||||
*/ |
||||
public Map<String, Object> queryAccessTokenList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { |
||||
Map<String, Object> result = new HashMap<>(5); |
||||
|
||||
PageInfo<AccessToken> pageInfo = new PageInfo<>(pageNo, pageSize); |
||||
Integer count; |
||||
List<AccessToken> accessTokenList; |
||||
if (loginUser.getUserType() == UserType.ADMIN_USER){ |
||||
count = accessTokenMapper.countAccessTokenPaging(0,searchVal); |
||||
accessTokenList = accessTokenMapper.queryAccessTokenPaging(0,searchVal, pageInfo.getStart(), pageSize); |
||||
}else { |
||||
count = accessTokenMapper.countAccessTokenPaging(loginUser.getId(),searchVal); |
||||
accessTokenList = accessTokenMapper.queryAccessTokenPaging(loginUser.getId(),searchVal, pageInfo.getStart(), pageSize); |
||||
} |
||||
|
||||
pageInfo.setTotalCount(count); |
||||
pageInfo.setLists(accessTokenList); |
||||
result.put(Constants.DATA_LIST, pageInfo); |
||||
putMsg(result, Status.SUCCESS); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* check |
||||
* |
||||
* @param result |
||||
* @param bool |
||||
* @param userNoOperationPerm |
||||
* @param status |
||||
* @return |
||||
*/ |
||||
private boolean check(Map<String, Object> result, boolean bool, Status userNoOperationPerm, String status) { |
||||
//only admin can operate
|
||||
if (bool) { |
||||
result.put(Constants.STATUS, userNoOperationPerm); |
||||
result.put(status, userNoOperationPerm.getMsg()); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* create token |
||||
* |
||||
* @param userId |
||||
* @param expireTime |
||||
* @param token |
||||
* @return |
||||
*/ |
||||
public Map<String, Object> createToken(int userId, String expireTime, String token) { |
||||
Map<String, Object> result = new HashMap<>(5); |
||||
|
||||
AccessToken accessToken = new AccessToken(); |
||||
accessToken.setUserId(userId); |
||||
accessToken.setExpireTime(DateUtils.stringToDate(expireTime)); |
||||
accessToken.setToken(token); |
||||
accessToken.setCreateTime(new Date()); |
||||
accessToken.setUpdateTime(new Date()); |
||||
|
||||
// insert
|
||||
int insert = accessTokenMapper.insert(accessToken); |
||||
|
||||
if (insert > 0) { |
||||
putMsg(result, Status.SUCCESS); |
||||
} else { |
||||
putMsg(result, Status.CREATE_ALERT_GROUP_ERROR); |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* generate token |
||||
* @param userId |
||||
* @param expireTime |
||||
* @return |
||||
*/ |
||||
public Map<String, Object> generateToken(int userId, String expireTime) { |
||||
Map<String, Object> result = new HashMap<>(5); |
||||
String token = EncryptionUtils.getMd5(userId + expireTime + String.valueOf(System.currentTimeMillis())); |
||||
result.put(Constants.DATA_LIST, token); |
||||
putMsg(result, Status.SUCCESS); |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* delete access token |
||||
* @param loginUser |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
public Map<String, Object> delAccessTokenById(User loginUser, int id) { |
||||
Map<String, Object> result = new HashMap<>(5); |
||||
//only admin can operate
|
||||
if (!isAdmin(loginUser)) { |
||||
putMsg(result, Status.USER_NOT_EXIST, id); |
||||
return result; |
||||
} |
||||
|
||||
accessTokenMapper.delete(id); |
||||
putMsg(result, Status.SUCCESS); |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* update token by id |
||||
* @param id |
||||
* @param userId |
||||
* @param expireTime |
||||
* @param token |
||||
* @return |
||||
*/ |
||||
public Map<String, Object> updateToken(int id,int userId, String expireTime, String token) { |
||||
Map<String, Object> result = new HashMap<>(5); |
||||
AccessToken accessToken = new AccessToken(); |
||||
accessToken.setId(id); |
||||
accessToken.setUserId(userId); |
||||
accessToken.setExpireTime(DateUtils.stringToDate(expireTime)); |
||||
accessToken.setToken(token); |
||||
accessToken.setUpdateTime(new Date()); |
||||
|
||||
accessTokenMapper.update(accessToken); |
||||
|
||||
putMsg(result, Status.SUCCESS); |
||||
return result; |
||||
} |
||||
} |
@ -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,162 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
import java.io.File; |
||||
import java.net.URI; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.UUID; |
||||
|
||||
import cn.escheduler.common.utils.EncryptionUtils; |
||||
import org.apache.commons.io.FileUtils; |
||||
import org.apache.http.NameValuePair; |
||||
import org.apache.http.client.entity.UrlEncodedFormEntity; |
||||
import org.apache.http.client.methods.CloseableHttpResponse; |
||||
import org.apache.http.client.methods.HttpGet; |
||||
import org.apache.http.client.methods.HttpPost; |
||||
import org.apache.http.client.utils.URIBuilder; |
||||
import org.apache.http.impl.client.CloseableHttpClient; |
||||
import org.apache.http.impl.client.HttpClients; |
||||
import org.apache.http.message.BasicNameValuePair; |
||||
import org.apache.http.util.EntityUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
public class HttpClientTest { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(HttpClientTest.class); |
||||
|
||||
public static void main(String[] args) throws Exception { |
||||
// doGETParamPathVariableAndChinese();
|
||||
// doGETParam();
|
||||
// doPOSTParam();
|
||||
|
||||
String md5 = EncryptionUtils.getMd5(String.valueOf(System.currentTimeMillis()) + "张三"); |
||||
System.out.println(md5); |
||||
System.out.println(md5.length()); |
||||
} |
||||
|
||||
public static void doPOSTParam()throws Exception{ |
||||
// create Httpclient
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault(); |
||||
// 创建http POST请求
|
||||
HttpPost httpPost = new HttpPost("http://127.0.0.1:12345/escheduler/projects/create"); |
||||
httpPost.setHeader("token", "123"); |
||||
// set parameters
|
||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>(); |
||||
parameters.add(new BasicNameValuePair("projectName", "qzw")); |
||||
parameters.add(new BasicNameValuePair("desc", "qzw")); |
||||
|
||||
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(parameters); |
||||
httpPost.setEntity(formEntity); |
||||
|
||||
|
||||
CloseableHttpResponse response = null; |
||||
try { |
||||
// execute
|
||||
response = httpclient.execute(httpPost); |
||||
// eponse status code 200
|
||||
if (response.getStatusLine().getStatusCode() == 200) { |
||||
String content = EntityUtils.toString(response.getEntity(), "UTF-8"); |
||||
System.out.println(content); |
||||
} |
||||
} finally { |
||||
if (response != null) { |
||||
response.close(); |
||||
} |
||||
httpclient.close(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @throws Exception |
||||
*/ |
||||
public static void doGETParamPathVariableAndChinese()throws Exception{ |
||||
// create HttpClient
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault(); |
||||
|
||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>(); |
||||
// parameters.add(new BasicNameValuePair("pageSize", "10"));
|
||||
|
||||
// define the parameters of the request
|
||||
URI uri = new URIBuilder("http://127.0.0.1:12345/escheduler/projects/%E5%85%A8%E9%83%A8%E6%B5%81%E7%A8%8B%E6%B5%8B%E8%AF%95/process/list") |
||||
.build(); |
||||
|
||||
// create http GET request
|
||||
HttpGet httpGet = new HttpGet(uri); |
||||
httpGet.setHeader("token","123"); |
||||
//response object
|
||||
CloseableHttpResponse response = null; |
||||
try { |
||||
// execute http get request
|
||||
response = httpclient.execute(httpGet); |
||||
// reponse status code 200
|
||||
if (response.getStatusLine().getStatusCode() == 200) { |
||||
String content = EntityUtils.toString(response.getEntity(), "UTF-8"); |
||||
logger.info("start--------------->"); |
||||
logger.info(content); |
||||
logger.info("end----------------->"); |
||||
} |
||||
} finally { |
||||
if (response != null) { |
||||
response.close(); |
||||
} |
||||
httpclient.close(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @throws Exception |
||||
*/ |
||||
public static void doGETParam()throws Exception{ |
||||
// create HttpClient
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault(); |
||||
|
||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>(); |
||||
parameters.add(new BasicNameValuePair("processInstanceId", "41415")); |
||||
|
||||
// define the parameters of the request
|
||||
URI uri = new URIBuilder("http://127.0.0.1:12345/escheduler/projects/%E5%85%A8%E9%83%A8%E6%B5%81%E7%A8%8B%E6%B5%8B%E8%AF%95/instance/view-variables") |
||||
.setParameters(parameters) |
||||
.build(); |
||||
|
||||
// create http GET request
|
||||
HttpGet httpGet = new HttpGet(uri); |
||||
httpGet.setHeader("token","123"); |
||||
//response object
|
||||
CloseableHttpResponse response = null; |
||||
try { |
||||
// execute http get request
|
||||
response = httpclient.execute(httpGet); |
||||
// reponse status code 200
|
||||
if (response.getStatusLine().getStatusCode() == 200) { |
||||
String content = EntityUtils.toString(response.getEntity(), "UTF-8"); |
||||
logger.info("start--------------->"); |
||||
logger.info(content); |
||||
logger.info("end----------------->"); |
||||
} |
||||
} finally { |
||||
if (response != null) { |
||||
response.close(); |
||||
} |
||||
httpclient.close(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,75 @@
|
||||
/* |
||||
* 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.common.job.db; |
||||
|
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.sql.Connection; |
||||
import java.sql.DriverManager; |
||||
import java.sql.SQLException; |
||||
|
||||
/** |
||||
* data source of ClickHouse |
||||
*/ |
||||
public class ClickHouseDataSource extends BaseDataSource { |
||||
private static final Logger logger = LoggerFactory.getLogger(ClickHouseDataSource.class); |
||||
|
||||
/** |
||||
* gets the JDBC url for the data source connection |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public String getJdbcUrl() { |
||||
String jdbcUrl = getAddress(); |
||||
if (jdbcUrl.lastIndexOf("/") != (jdbcUrl.length() - 1)) { |
||||
jdbcUrl += "/"; |
||||
} |
||||
|
||||
jdbcUrl += getDatabase(); |
||||
|
||||
if (StringUtils.isNotEmpty(getOther())) { |
||||
jdbcUrl += "?" + getOther(); |
||||
} |
||||
|
||||
return jdbcUrl; |
||||
} |
||||
|
||||
/** |
||||
* test whether the data source can be connected successfully |
||||
* @throws Exception |
||||
*/ |
||||
@Override |
||||
public void isConnectable() throws Exception { |
||||
Connection con = null; |
||||
try { |
||||
Class.forName("ru.yandex.clickhouse.ClickHouseDriver"); |
||||
con = DriverManager.getConnection(getJdbcUrl(), getUser(), getPassword()); |
||||
} finally { |
||||
if (con != null) { |
||||
try { |
||||
con.close(); |
||||
} catch (SQLException e) { |
||||
logger.error("ClickHouse datasource try conn close conn error", e); |
||||
throw e; |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,75 @@
|
||||
/* |
||||
* 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.common.job.db; |
||||
|
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.sql.Connection; |
||||
import java.sql.DriverManager; |
||||
import java.sql.SQLException; |
||||
|
||||
/** |
||||
* data source of Oracle |
||||
*/ |
||||
public class OracleDataSource extends BaseDataSource { |
||||
private static final Logger logger = LoggerFactory.getLogger(OracleDataSource.class); |
||||
|
||||
/** |
||||
* gets the JDBC url for the data source connection |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public String getJdbcUrl() { |
||||
String jdbcUrl = getAddress(); |
||||
if (jdbcUrl.lastIndexOf("/") != (jdbcUrl.length() - 1)) { |
||||
jdbcUrl += "/"; |
||||
} |
||||
|
||||
jdbcUrl += getDatabase(); |
||||
|
||||
if (StringUtils.isNotEmpty(getOther())) { |
||||
jdbcUrl += "?" + getOther(); |
||||
} |
||||
|
||||
return jdbcUrl; |
||||
} |
||||
|
||||
/** |
||||
* test whether the data source can be connected successfully |
||||
* @throws Exception |
||||
*/ |
||||
@Override |
||||
public void isConnectable() throws Exception { |
||||
Connection con = null; |
||||
try { |
||||
Class.forName("oracle.jdbc.driver.OracleDriver"); |
||||
con = DriverManager.getConnection(getJdbcUrl(), getUser(), getPassword()); |
||||
} finally { |
||||
if (con != null) { |
||||
try { |
||||
con.close(); |
||||
} catch (SQLException e) { |
||||
logger.error("Oracle datasource try conn close conn error", e); |
||||
throw e; |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,71 @@
|
||||
/* |
||||
* 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.common.job.db; |
||||
|
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.sql.Connection; |
||||
import java.sql.DriverManager; |
||||
import java.sql.SQLException; |
||||
|
||||
/** |
||||
* data source of SQL Server |
||||
*/ |
||||
public class SQLServerDataSource extends BaseDataSource { |
||||
private static final Logger logger = LoggerFactory.getLogger(SQLServerDataSource.class); |
||||
|
||||
/** |
||||
* gets the JDBC url for the data source connection |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public String getJdbcUrl() { |
||||
String jdbcUrl = getAddress(); |
||||
jdbcUrl += ";databaseName=" + getDatabase(); |
||||
|
||||
if (StringUtils.isNotEmpty(getOther())) { |
||||
jdbcUrl += ";" + getOther(); |
||||
} |
||||
|
||||
return jdbcUrl; |
||||
} |
||||
|
||||
/** |
||||
* test whether the data source can be connected successfully |
||||
* @throws Exception |
||||
*/ |
||||
@Override |
||||
public void isConnectable() throws Exception { |
||||
Connection con = null; |
||||
try { |
||||
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); |
||||
con = DriverManager.getConnection(getJdbcUrl(), getUser(), getPassword()); |
||||
} finally { |
||||
if (con != null) { |
||||
try { |
||||
con.close(); |
||||
} catch (SQLException e) { |
||||
logger.error("SQL Server datasource try conn close conn error", e); |
||||
throw e; |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,104 @@
|
||||
/* |
||||
* 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.common.utils; |
||||
|
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.sql.*; |
||||
|
||||
public class MysqlUtil { |
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(MysqlUtil.class); |
||||
|
||||
private static MysqlUtil instance; |
||||
|
||||
MysqlUtil() { |
||||
} |
||||
|
||||
public static MysqlUtil getInstance() { |
||||
if (null == instance) { |
||||
syncInit(); |
||||
} |
||||
return instance; |
||||
} |
||||
|
||||
private static synchronized void syncInit() { |
||||
if (instance == null) { |
||||
instance = new MysqlUtil(); |
||||
} |
||||
} |
||||
|
||||
public void release(ResultSet rs, Statement stmt, Connection conn) { |
||||
try { |
||||
if (rs != null) { |
||||
rs.close(); |
||||
rs = null; |
||||
} |
||||
} catch (SQLException e) { |
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException(e); |
||||
} finally { |
||||
try { |
||||
if (stmt != null) { |
||||
stmt.close(); |
||||
stmt = null; |
||||
} |
||||
} catch (SQLException e) { |
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException(e); |
||||
} finally { |
||||
try { |
||||
if (conn != null) { |
||||
conn.close(); |
||||
conn = null; |
||||
} |
||||
} catch (SQLException e) { |
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static void realeaseResource(ResultSet rs, PreparedStatement ps, Connection conn) { |
||||
MysqlUtil.getInstance().release(rs,ps,conn); |
||||
if (null != rs) { |
||||
try { |
||||
rs.close(); |
||||
} catch (SQLException e) { |
||||
logger.error(e.getMessage(),e); |
||||
} |
||||
} |
||||
|
||||
if (null != ps) { |
||||
try { |
||||
ps.close(); |
||||
} catch (SQLException e) { |
||||
logger.error(e.getMessage(),e); |
||||
} |
||||
} |
||||
|
||||
if (null != conn) { |
||||
try { |
||||
conn.close(); |
||||
} catch (SQLException e) { |
||||
logger.error(e.getMessage(),e); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,150 @@
|
||||
/* |
||||
* 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.common.utils; |
||||
|
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileInputStream; |
||||
import java.io.FileNotFoundException; |
||||
import java.io.IOException; |
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.Comparator; |
||||
import java.util.List; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
/** |
||||
* Metadata related common classes |
||||
* |
||||
*/ |
||||
public class SchemaUtils { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SchemaUtils.class); |
||||
private static Pattern p = Pattern.compile("\\s*|\t|\r|\n"); |
||||
|
||||
/** |
||||
* 获取所有upgrade目录下的可升级的schema |
||||
* Gets upgradable schemas for all upgrade directories |
||||
* @return |
||||
*/ |
||||
@SuppressWarnings("unchecked") |
||||
public static List<String> getAllSchemaList() { |
||||
List<String> schemaDirList = new ArrayList<>(); |
||||
File[] schemaDirArr = FileUtils.getAllDir("sql/upgrade"); |
||||
if(schemaDirArr == null || schemaDirArr.length == 0) { |
||||
return null; |
||||
} |
||||
|
||||
for(File file : schemaDirArr) { |
||||
schemaDirList.add(file.getName()); |
||||
} |
||||
|
||||
Collections.sort(schemaDirList , new Comparator() { |
||||
@Override |
||||
public int compare(Object o1 , Object o2){ |
||||
try { |
||||
String dir1 = String.valueOf(o1); |
||||
String dir2 = String.valueOf(o2); |
||||
String version1 = dir1.split("_")[0]; |
||||
String version2 = dir2.split("_")[0]; |
||||
if(version1.equals(version2)) { |
||||
return 0; |
||||
} |
||||
|
||||
if(SchemaUtils.isAGreatVersion(version1, version2)) { |
||||
return 1; |
||||
} |
||||
|
||||
return -1; |
||||
|
||||
} catch (Exception e) { |
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
return schemaDirList; |
||||
} |
||||
|
||||
/** |
||||
* 判断schemaVersion是否比version版本高 |
||||
* Determine whether schemaVersion is higher than version |
||||
* @param schemaVersion |
||||
* @param version |
||||
* @return |
||||
*/ |
||||
public static boolean isAGreatVersion(String schemaVersion, String version) { |
||||
if(StringUtils.isEmpty(schemaVersion) || StringUtils.isEmpty(version)) { |
||||
throw new RuntimeException("schemaVersion or version is empty"); |
||||
} |
||||
|
||||
String[] schemaVersionArr = schemaVersion.split("\\."); |
||||
String[] versionArr = version.split("\\."); |
||||
int arrLength = schemaVersionArr.length < versionArr.length ? schemaVersionArr.length : versionArr.length; |
||||
for(int i = 0 ; i < arrLength ; i++) { |
||||
if(Integer.valueOf(schemaVersionArr[i]) > Integer.valueOf(versionArr[i])) { |
||||
return true; |
||||
}else if(Integer.valueOf(schemaVersionArr[i]) < Integer.valueOf(versionArr[i])) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
// 说明直到第arrLength-1个元素,两个版本号都一样,此时谁的arrLength大,谁的版本号就大
|
||||
// If the version and schema version is the same from 0 up to the arrlength-1 element,whoever has a larger arrLength has a larger version number
|
||||
return schemaVersionArr.length > versionArr.length; |
||||
} |
||||
|
||||
/** |
||||
* Gets the current software version number of the system |
||||
* @return |
||||
*/ |
||||
public static String getSoftVersion() { |
||||
String soft_version; |
||||
try { |
||||
soft_version = FileUtils.readFile2Str(new FileInputStream(new File("sql/soft_version"))); |
||||
soft_version = replaceBlank(soft_version); |
||||
} catch (FileNotFoundException e) { |
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException("Failed to get the product version description file. The file could not be found", e); |
||||
} catch (IOException e) { |
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException("Failed to get product version number description file, failed to read the file", e); |
||||
} |
||||
return soft_version; |
||||
} |
||||
|
||||
/** |
||||
* 去掉字符串中的空格回车换行和制表符 |
||||
* Strips the string of space carriage returns and tabs |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static String replaceBlank(String str) { |
||||
String dest = ""; |
||||
if (str!=null) { |
||||
|
||||
Matcher m = p.matcher(str); |
||||
dest = m.replaceAll(""); |
||||
} |
||||
return dest; |
||||
} |
||||
} |
@ -0,0 +1,317 @@
|
||||
/* |
||||
* 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.common.utils; |
||||
|
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.LineNumberReader; |
||||
import java.io.Reader; |
||||
import java.sql.*; |
||||
|
||||
/* |
||||
* Slightly modified version of the com.ibatis.common.jdbc.ScriptRunner class
|
||||
* from the iBATIS Apache project. Only removed dependency on Resource class
|
||||
* and a constructor |
||||
*/ |
||||
/* |
||||
* Copyright 2004 Clinton Begin |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
/** |
||||
* Tool to run database scripts |
||||
*/ |
||||
public class ScriptRunner { |
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(ScriptRunner.class); |
||||
|
||||
private static final String DEFAULT_DELIMITER = ";"; |
||||
|
||||
private Connection connection; |
||||
|
||||
private boolean stopOnError; |
||||
private boolean autoCommit; |
||||
|
||||
private String delimiter = DEFAULT_DELIMITER; |
||||
private boolean fullLineDelimiter = false; |
||||
|
||||
/** |
||||
* Default constructor |
||||
*/ |
||||
public ScriptRunner(Connection connection, boolean autoCommit, boolean stopOnError) { |
||||
this.connection = connection; |
||||
this.autoCommit = autoCommit; |
||||
this.stopOnError = stopOnError; |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
String dbName = "db_mmu"; |
||||
String appKey = dbName.substring(dbName.lastIndexOf("_")+1, dbName.length()); |
||||
System.out.println(appKey); |
||||
} |
||||
|
||||
public void setDelimiter(String delimiter, boolean fullLineDelimiter) { |
||||
this.delimiter = delimiter; |
||||
this.fullLineDelimiter = fullLineDelimiter; |
||||
} |
||||
|
||||
/** |
||||
* Runs an SQL script (read in using the Reader parameter) |
||||
* |
||||
* @param reader |
||||
* - the source of the script |
||||
*/ |
||||
public void runScript(Reader reader) throws IOException, SQLException { |
||||
try { |
||||
boolean originalAutoCommit = connection.getAutoCommit(); |
||||
try { |
||||
if (originalAutoCommit != this.autoCommit) { |
||||
connection.setAutoCommit(this.autoCommit); |
||||
} |
||||
runScript(connection, reader); |
||||
} finally { |
||||
connection.setAutoCommit(originalAutoCommit); |
||||
} |
||||
} catch (IOException e) { |
||||
throw e; |
||||
} catch (SQLException e) { |
||||
throw e; |
||||
} catch (Exception e) { |
||||
throw new RuntimeException("Error running script. Cause: " + e, e); |
||||
} |
||||
} |
||||
|
||||
public void runScript(Reader reader, String dbName) throws IOException, SQLException { |
||||
try { |
||||
boolean originalAutoCommit = connection.getAutoCommit(); |
||||
try { |
||||
if (originalAutoCommit != this.autoCommit) { |
||||
connection.setAutoCommit(this.autoCommit); |
||||
} |
||||
runScript(connection, reader, dbName); |
||||
} finally { |
||||
connection.setAutoCommit(originalAutoCommit); |
||||
} |
||||
} catch (IOException e) { |
||||
throw e; |
||||
} catch (SQLException e) { |
||||
throw e; |
||||
} catch (Exception e) { |
||||
throw new RuntimeException("Error running script. Cause: " + e, e); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Runs an SQL script (read in using the Reader parameter) using the connection |
||||
* passed in |
||||
* |
||||
* @param conn |
||||
* - the connection to use for the script |
||||
* @param reader |
||||
* - the source of the script |
||||
* @throws SQLException |
||||
* if any SQL errors occur |
||||
* @throws IOException |
||||
* if there is an error reading from the Reader |
||||
*/ |
||||
private void runScript(Connection conn, Reader reader) throws IOException, SQLException { |
||||
StringBuffer command = null; |
||||
try { |
||||
LineNumberReader lineReader = new LineNumberReader(reader); |
||||
String line = null; |
||||
while ((line = lineReader.readLine()) != null) { |
||||
if (command == null) { |
||||
command = new StringBuffer(); |
||||
} |
||||
String trimmedLine = line.trim(); |
||||
if (trimmedLine.startsWith("--")) { |
||||
logger.info(trimmedLine); |
||||
} else if (trimmedLine.length() < 1 || trimmedLine.startsWith("//")) { |
||||
// Do nothing
|
||||
} else if (trimmedLine.length() < 1 || trimmedLine.startsWith("--")) { |
||||
// Do nothing
|
||||
|
||||
} else if (trimmedLine.startsWith("delimiter")) { |
||||
String newDelimiter = trimmedLine.split(" ")[1]; |
||||
this.setDelimiter(newDelimiter, fullLineDelimiter); |
||||
|
||||
} else if (!fullLineDelimiter && trimmedLine.endsWith(getDelimiter()) |
||||
|| fullLineDelimiter && trimmedLine.equals(getDelimiter())) { |
||||
command.append(line.substring(0, line.lastIndexOf(getDelimiter()))); |
||||
command.append(" "); |
||||
Statement statement = conn.createStatement(); |
||||
|
||||
// logger.info(command.toString());
|
||||
|
||||
boolean hasResults = false; |
||||
logger.info("sql:"+command.toString()); |
||||
if (stopOnError) { |
||||
hasResults = statement.execute(command.toString()); |
||||
} else { |
||||
try { |
||||
statement.execute(command.toString()); |
||||
} catch (SQLException e) { |
||||
logger.error(e.getMessage(),e); |
||||
throw e; |
||||
} |
||||
} |
||||
|
||||
ResultSet rs = statement.getResultSet(); |
||||
if (hasResults && rs != null) { |
||||
ResultSetMetaData md = rs.getMetaData(); |
||||
int cols = md.getColumnCount(); |
||||
for (int i = 0; i < cols; i++) { |
||||
String name = md.getColumnLabel(i); |
||||
logger.info(name + "\t"); |
||||
} |
||||
logger.info(""); |
||||
while (rs.next()) { |
||||
for (int i = 0; i < cols; i++) { |
||||
String value = rs.getString(i); |
||||
logger.info(value + "\t"); |
||||
} |
||||
logger.info(""); |
||||
} |
||||
} |
||||
|
||||
command = null; |
||||
try { |
||||
statement.close(); |
||||
} catch (Exception e) { |
||||
// Ignore to workaround a bug in Jakarta DBCP
|
||||
} |
||||
Thread.yield(); |
||||
} else { |
||||
command.append(line); |
||||
command.append(" "); |
||||
} |
||||
} |
||||
|
||||
} catch (SQLException e) { |
||||
logger.error("Error executing: " + command.toString()); |
||||
throw e; |
||||
} catch (IOException e) { |
||||
e.fillInStackTrace(); |
||||
logger.error("Error executing: " + command.toString()); |
||||
throw e; |
||||
} |
||||
} |
||||
|
||||
private void runScript(Connection conn, Reader reader , String dbName) throws IOException, SQLException { |
||||
StringBuffer command = null; |
||||
String sql = ""; |
||||
String appKey = dbName.substring(dbName.lastIndexOf("_")+1, dbName.length()); |
||||
try { |
||||
LineNumberReader lineReader = new LineNumberReader(reader); |
||||
String line = null; |
||||
while ((line = lineReader.readLine()) != null) { |
||||
if (command == null) { |
||||
command = new StringBuffer(); |
||||
} |
||||
String trimmedLine = line.trim(); |
||||
if (trimmedLine.startsWith("--")) { |
||||
logger.info(trimmedLine); |
||||
} else if (trimmedLine.length() < 1 || trimmedLine.startsWith("//")) { |
||||
// Do nothing
|
||||
} else if (trimmedLine.length() < 1 || trimmedLine.startsWith("--")) { |
||||
// Do nothing
|
||||
|
||||
} else if (trimmedLine.startsWith("delimiter")) { |
||||
String newDelimiter = trimmedLine.split(" ")[1]; |
||||
this.setDelimiter(newDelimiter, fullLineDelimiter); |
||||
|
||||
} else if (!fullLineDelimiter && trimmedLine.endsWith(getDelimiter()) |
||||
|| fullLineDelimiter && trimmedLine.equals(getDelimiter())) { |
||||
command.append(line.substring(0, line.lastIndexOf(getDelimiter()))); |
||||
command.append(" "); |
||||
Statement statement = conn.createStatement(); |
||||
|
||||
// logger.info(command.toString());
|
||||
|
||||
sql = command.toString().replaceAll("\\{\\{APPDB\\}\\}", dbName); |
||||
boolean hasResults = false; |
||||
logger.info("sql:"+sql); |
||||
if (stopOnError) { |
||||
hasResults = statement.execute(sql); |
||||
} else { |
||||
try { |
||||
statement.execute(sql); |
||||
} catch (SQLException e) { |
||||
logger.error(e.getMessage(),e); |
||||
throw e; |
||||
} |
||||
} |
||||
|
||||
ResultSet rs = statement.getResultSet(); |
||||
if (hasResults && rs != null) { |
||||
ResultSetMetaData md = rs.getMetaData(); |
||||
int cols = md.getColumnCount(); |
||||
for (int i = 0; i < cols; i++) { |
||||
String name = md.getColumnLabel(i); |
||||
logger.info(name + "\t"); |
||||
} |
||||
logger.info(""); |
||||
while (rs.next()) { |
||||
for (int i = 0; i < cols; i++) { |
||||
String value = rs.getString(i); |
||||
logger.info(value + "\t"); |
||||
} |
||||
logger.info(""); |
||||
} |
||||
} |
||||
|
||||
command = null; |
||||
try { |
||||
statement.close(); |
||||
} catch (Exception e) { |
||||
// Ignore to workaround a bug in Jakarta DBCP
|
||||
} |
||||
Thread.yield(); |
||||
} else { |
||||
command.append(line); |
||||
command.append(" "); |
||||
} |
||||
} |
||||
|
||||
} catch (SQLException e) { |
||||
logger.error("Error executing: " + sql); |
||||
throw e; |
||||
} catch (IOException e) { |
||||
e.fillInStackTrace(); |
||||
logger.error("Error executing: " + sql); |
||||
throw e; |
||||
} |
||||
} |
||||
|
||||
private String getDelimiter() { |
||||
return delimiter; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,54 @@
|
||||
-- 用户指定队列 |
||||
alter table t_escheduler_user add queue varchar(64); |
||||
|
||||
-- 访问token |
||||
CREATE TABLE `t_escheduler_access_token` ( |
||||
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键', |
||||
`user_id` int(11) DEFAULT NULL COMMENT '用户id', |
||||
`token` varchar(64) DEFAULT NULL COMMENT 'token令牌', |
||||
`expire_time` datetime DEFAULT NULL COMMENT 'token有效结束时间', |
||||
`create_time` datetime DEFAULT NULL COMMENT '创建时间', |
||||
`update_time` datetime DEFAULT NULL COMMENT '更新时间', |
||||
PRIMARY KEY (`id`) |
||||
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8; |
||||
|
||||
CREATE TABLE `t_escheduler_error_command` ( |
||||
`id` int(11) NOT NULL COMMENT '主键', |
||||
`command_type` tinyint(4) NULL DEFAULT NULL COMMENT '命令类型:0 启动工作流,1 从当前节点开始执行,2 恢复被容错的工作流,3 恢复暂停流程,4 从失败节点开始执行,5 补数,6 调度,7 重跑,8 暂停,9 停止,10 恢复等待线程', |
||||
`executor_id` int(11) NULL DEFAULT NULL COMMENT '命令执行者', |
||||
`process_definition_id` int(11) NULL DEFAULT NULL COMMENT '流程定义id', |
||||
`command_param` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '命令的参数(json格式)', |
||||
`task_depend_type` tinyint(4) NULL DEFAULT NULL COMMENT '节点依赖类型', |
||||
`failure_strategy` tinyint(4) NULL DEFAULT 0 COMMENT '失败策略:0结束,1继续', |
||||
`warning_type` tinyint(4) NULL DEFAULT 0 COMMENT '告警类型', |
||||
`warning_group_id` int(11) NULL DEFAULT NULL COMMENT '告警组', |
||||
`schedule_time` datetime(0) NULL DEFAULT NULL COMMENT '预期运行时间', |
||||
`start_time` datetime(0) NULL DEFAULT NULL COMMENT '开始时间', |
||||
`update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间', |
||||
`dependence` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '依赖字段', |
||||
`process_instance_priority` int(11) NULL DEFAULT NULL COMMENT '流程实例优先级:0 Highest,1 High,2 Medium,3 Low,4 Lowest', |
||||
`message` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '执行信息', |
||||
PRIMARY KEY (`id`) USING BTREE |
||||
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; |
||||
|
||||
|
||||
CREATE TABLE `t_escheduler_worker_group` ( |
||||
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'id', |
||||
`name` varchar(256) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL COMMENT '组名称', |
||||
`ip_list` varchar(256) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL COMMENT 'worker地址列表', |
||||
`create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', |
||||
`update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间', |
||||
PRIMARY KEY (`id`) USING BTREE |
||||
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; |
||||
|
||||
ALTER TABLE `t_escheduler_task_instance` |
||||
ADD COLUMN `worker_group_id` int(11) NULL DEFAULT -1 COMMENT '任务指定运行的worker分组' AFTER `task_instance_priority`; |
||||
|
||||
ALTER TABLE `t_escheduler_command` |
||||
ADD COLUMN `worker_group_id` int(11) NULL DEFAULT -1 COMMENT '任务指定运行的worker分组' NULL AFTER `process_instance_priority`; |
||||
|
||||
ALTER TABLE `t_escheduler_error_command` |
||||
ADD COLUMN `worker_group_id` int(11) NULL DEFAULT -1 COMMENT '任务指定运行的worker分组' NULL AFTER `process_instance_priority`; |
||||
|
||||
ALTER TABLE `t_escheduler_schedules` |
||||
ADD COLUMN `worker_group_id` int(11) NULL DEFAULT -1 COMMENT '任务指定运行的worker分组' NULL AFTER `process_instance_priority`; |
@ -0,0 +1,90 @@
|
||||
/* |
||||
* 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.common.enums.UserType; |
||||
import cn.escheduler.dao.model.AccessToken; |
||||
import cn.escheduler.dao.model.User; |
||||
import org.apache.ibatis.annotations.*; |
||||
import org.apache.ibatis.type.EnumOrdinalTypeHandler; |
||||
import org.apache.ibatis.type.JdbcType; |
||||
|
||||
import java.sql.Timestamp; |
||||
import java.util.List; |
||||
|
||||
public interface AccessTokenMapper { |
||||
|
||||
/** |
||||
* insert accessToken |
||||
* @param accessToken |
||||
* @return |
||||
*/ |
||||
@InsertProvider(type = AccessTokenMapperProvider.class, method = "insert") |
||||
@Options(useGeneratedKeys = true,keyProperty = "accessToken.id") |
||||
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "accessToken.id", before = false, resultType = int.class) |
||||
int insert(@Param("accessToken") AccessToken accessToken); |
||||
|
||||
|
||||
/** |
||||
* delete accessToken |
||||
* @param accessTokenId |
||||
* @return |
||||
*/ |
||||
@DeleteProvider(type = AccessTokenMapperProvider.class, method = "delete") |
||||
int delete(@Param("accessTokenId") int accessTokenId); |
||||
|
||||
|
||||
/** |
||||
* update accessToken |
||||
* |
||||
* @param accessToken |
||||
* @return |
||||
*/ |
||||
@UpdateProvider(type = AccessTokenMapperProvider.class, method = "update") |
||||
int update(@Param("accessToken") AccessToken accessToken); |
||||
|
||||
|
||||
/** |
||||
* query access token list paging |
||||
* @param searchVal |
||||
* @param offset |
||||
* @param pageSize |
||||
* @return |
||||
*/ |
||||
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER), |
||||
@Result(property = "userId", column = "user_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER), |
||||
@Result(property = "token", column = "token", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||
@Result(property = "userName", column = "user_name", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||
@Result(property = "expireTime", column = "expire_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE), |
||||
@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 = AccessTokenMapperProvider.class, method = "queryAccessTokenPaging") |
||||
List<AccessToken> queryAccessTokenPaging(@Param("userId") Integer userId, |
||||
@Param("searchVal") String searchVal, |
||||
@Param("offset") Integer offset, |
||||
@Param("pageSize") Integer pageSize); |
||||
|
||||
/** |
||||
* count access token by search value |
||||
* @param searchVal |
||||
* @return |
||||
*/ |
||||
@SelectProvider(type = AccessTokenMapperProvider.class, method = "countAccessTokenPaging") |
||||
Integer countAccessTokenPaging(@Param("userId") Integer userId |
||||
,@Param("searchVal") String searchVal); |
||||
} |
@ -0,0 +1,136 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
/** |
||||
* access token mapper provider |
||||
* |
||||
*/ |
||||
public class AccessTokenMapperProvider { |
||||
|
||||
private static final String TABLE_NAME = "t_escheduler_access_token"; |
||||
|
||||
/** |
||||
* insert accessToken |
||||
* |
||||
* @param parameter |
||||
* @return |
||||
*/ |
||||
public String insert(Map<String, Object> parameter) { |
||||
return new SQL() { |
||||
{ |
||||
INSERT_INTO(TABLE_NAME); |
||||
VALUES("`user_id`", "#{accessToken.userId}"); |
||||
VALUES("`token`", "#{accessToken.token}"); |
||||
VALUES("`expire_time`", "#{accessToken.expireTime}");; |
||||
VALUES("`create_time`", "#{accessToken.createTime}"); |
||||
VALUES("`update_time`", "#{accessToken.updateTime}"); |
||||
} |
||||
}.toString(); |
||||
} |
||||
|
||||
/** |
||||
* delete accessToken |
||||
* |
||||
* @param parameter |
||||
* @return |
||||
*/ |
||||
public String delete(Map<String, Object> parameter) { |
||||
return new SQL() { |
||||
{ |
||||
DELETE_FROM(TABLE_NAME); |
||||
|
||||
WHERE("`id`=#{accessTokenId}"); |
||||
} |
||||
}.toString(); |
||||
} |
||||
|
||||
/** |
||||
* update accessToken |
||||
* |
||||
* @param parameter |
||||
* @return |
||||
*/ |
||||
public String update(Map<String, Object> parameter) { |
||||
return new SQL() { |
||||
{ |
||||
UPDATE(TABLE_NAME); |
||||
|
||||
SET("`user_id`=#{accessToken.userId}"); |
||||
SET("`token`=#{accessToken.token}"); |
||||
SET("`expire_time`=#{accessToken.expireTime}"); |
||||
SET("`update_time`=#{accessToken.updateTime}"); |
||||
|
||||
WHERE("`id`=#{accessToken.id}"); |
||||
} |
||||
}.toString(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* count user number by search value |
||||
* @param parameter |
||||
* @return |
||||
*/ |
||||
public String countAccessTokenPaging(Map<String, Object> parameter) { |
||||
return new SQL() {{ |
||||
SELECT("count(0)"); |
||||
FROM(TABLE_NAME + " t,t_escheduler_user u"); |
||||
Object searchVal = parameter.get("searchVal"); |
||||
WHERE("u.id = t.user_id"); |
||||
if(parameter.get("userId") != null && (int)parameter.get("userId") != 0){ |
||||
WHERE(" u.id = #{userId}"); |
||||
} |
||||
if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){ |
||||
WHERE(" u.user_name like concat('%', #{searchVal}, '%')"); |
||||
} |
||||
}}.toString(); |
||||
} |
||||
|
||||
/** |
||||
* query user list paging |
||||
* @param parameter |
||||
* @return |
||||
*/ |
||||
public String queryAccessTokenPaging(Map<String, Object> parameter) { |
||||
return new SQL() { |
||||
{ |
||||
SELECT("t.*,u.user_name"); |
||||
FROM(TABLE_NAME + " t,t_escheduler_user u"); |
||||
Object searchVal = parameter.get("searchVal"); |
||||
WHERE("u.id = t.user_id"); |
||||
if(parameter.get("userId") != null && (int)parameter.get("userId") != 0){ |
||||
WHERE(" u.id = #{userId}"); |
||||
} |
||||
if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){ |
||||
WHERE(" u.user_name like concat('%', #{searchVal}, '%') "); |
||||
} |
||||
ORDER_BY(" t.update_time desc limit #{offset},#{pageSize} "); |
||||
} |
||||
}.toString(); |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,59 @@
|
||||
/* |
||||
* 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.common.enums.*; |
||||
import cn.escheduler.dao.model.Command; |
||||
import cn.escheduler.dao.model.ErrorCommand; |
||||
import cn.escheduler.dao.model.ExecuteStatusCount; |
||||
import org.apache.ibatis.annotations.*; |
||||
import org.apache.ibatis.type.EnumOrdinalTypeHandler; |
||||
import org.apache.ibatis.type.JdbcType; |
||||
|
||||
import java.sql.Timestamp; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* command mapper |
||||
*/ |
||||
public interface ErrorCommandMapper { |
||||
|
||||
/** |
||||
* inert error command |
||||
* @param errorCommand |
||||
* @return |
||||
*/ |
||||
@InsertProvider(type = ErrorCommandMapperProvider.class, method = "insert") |
||||
@Options(useGeneratedKeys = true,keyProperty = "errorCommand.id") |
||||
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "errorCommand.id", before = false, resultType = int.class) |
||||
int insert(@Param("errorCommand") ErrorCommand errorCommand); |
||||
|
||||
@Results(value = { |
||||
@Result(property = "state", column = "state", typeHandler = EnumOrdinalTypeHandler.class, javaType = ExecutionStatus.class, jdbcType = JdbcType.TINYINT), |
||||
@Result(property = "count", column = "count", javaType = Integer.class, jdbcType = JdbcType.INTEGER), |
||||
}) |
||||
@SelectProvider(type = ErrorCommandMapperProvider.class, method = "countCommandState") |
||||
List<ExecuteStatusCount> countCommandState( |
||||
@Param("userId") int userId, |
||||
@Param("userType") UserType userType, |
||||
@Param("startTime") Date startTime, |
||||
@Param("endTime") Date endTime, |
||||
@Param("projectId") int projectId); |
||||
|
||||
|
||||
} |
@ -0,0 +1,71 @@
|
||||
package cn.escheduler.dao.mapper; |
||||
|
||||
import cn.escheduler.common.enums.*; |
||||
import cn.escheduler.common.utils.EnumFieldUtil; |
||||
import org.apache.ibatis.jdbc.SQL; |
||||
|
||||
import java.util.Map; |
||||
|
||||
public class ErrorCommandMapperProvider { |
||||
|
||||
|
||||
private static final String TABLE_NAME = "t_escheduler_error_command"; |
||||
|
||||
|
||||
/** |
||||
* inert command |
||||
* |
||||
* @param parameter |
||||
* @return |
||||
*/ |
||||
public String insert(Map<String, Object> parameter) { |
||||
return new SQL() { |
||||
{ |
||||
INSERT_INTO(TABLE_NAME); |
||||
VALUES("`id`", "#{errorCommand.id}"); |
||||
VALUES("`command_type`", EnumFieldUtil.genFieldStr("errorCommand.commandType", CommandType.class)); |
||||
VALUES("`process_definition_id`", "#{errorCommand.processDefinitionId}"); |
||||
VALUES("`executor_id`", "#{errorCommand.executorId}"); |
||||
VALUES("`command_param`", "#{errorCommand.commandParam}"); |
||||
VALUES("`task_depend_type`", EnumFieldUtil.genFieldStr("errorCommand.taskDependType", TaskDependType.class)); |
||||
VALUES("`failure_strategy`", EnumFieldUtil.genFieldStr("errorCommand.failureStrategy", FailureStrategy.class)); |
||||
VALUES("`warning_type`", EnumFieldUtil.genFieldStr("errorCommand.warningType", WarningType.class)); |
||||
VALUES("`process_instance_priority`", EnumFieldUtil.genFieldStr("errorCommand.processInstancePriority", Priority.class)); |
||||
VALUES("`warning_group_id`", "#{errorCommand.warningGroupId}"); |
||||
VALUES("`schedule_time`", "#{errorCommand.scheduleTime}"); |
||||
VALUES("`update_time`", "#{errorCommand.updateTime}"); |
||||
VALUES("`start_time`", "#{errorCommand.startTime}"); |
||||
VALUES("`worker_group_id`", "#{errorCommand.workerGroupId}"); |
||||
VALUES("`message`", "#{errorCommand.message}"); |
||||
} |
||||
}.toString(); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* count command type |
||||
* @param parameter |
||||
* @return |
||||
*/ |
||||
public String countCommandState(Map<String, Object> parameter){ |
||||
return new SQL(){ |
||||
{ |
||||
SELECT("command_type as state,COUNT(*) AS count"); |
||||
FROM(TABLE_NAME + " cmd,t_escheduler_process_definition process"); |
||||
WHERE("cmd.process_definition_id = process.id"); |
||||
if(parameter.get("projectId") != null && (int)parameter.get("projectId") != 0){ |
||||
WHERE( "process.project_id = #{projectId} "); |
||||
}else{ |
||||
if(parameter.get("userType") != null && String.valueOf(parameter.get("userType")) == "GENERAL_USER") { |
||||
AND(); |
||||
WHERE("process.project_id in (select id as project_id from t_escheduler_project tp where tp.user_id= #{userId} " + |
||||
"union select project_id from t_escheduler_relation_project_user tr where tr.user_id= #{userId} )"); |
||||
|
||||
} |
||||
} |
||||
WHERE("cmd.start_time >= #{startTime} and cmd.update_time <= #{endTime}"); |
||||
GROUP_BY("cmd.command_type"); |
||||
} |
||||
}.toString(); |
||||
} |
||||
} |
@ -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,126 @@
|
||||
package cn.escheduler.dao.model; |
||||
|
||||
import java.util.Date; |
||||
|
||||
/* |
||||
* 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. |
||||
*/ |
||||
public class AccessToken { |
||||
|
||||
/** |
||||
* id |
||||
*/ |
||||
private int id; |
||||
|
||||
/** |
||||
* user id |
||||
*/ |
||||
private int userId; |
||||
|
||||
/** |
||||
* user name |
||||
*/ |
||||
private String userName; |
||||
|
||||
/** |
||||
* user token |
||||
*/ |
||||
private String token; |
||||
|
||||
/** |
||||
* token expire time |
||||
*/ |
||||
private Date expireTime; |
||||
|
||||
/** |
||||
* create time |
||||
*/ |
||||
private Date createTime; |
||||
|
||||
/** |
||||
* update time |
||||
*/ |
||||
private Date updateTime; |
||||
|
||||
public int getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(int id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public int getUserId() { |
||||
return userId; |
||||
} |
||||
|
||||
public void setUserId(int userId) { |
||||
this.userId = userId; |
||||
} |
||||
|
||||
public String getToken() { |
||||
return token; |
||||
} |
||||
|
||||
public void setToken(String token) { |
||||
this.token = token; |
||||
} |
||||
|
||||
public Date getExpireTime() { |
||||
return expireTime; |
||||
} |
||||
|
||||
public void setExpireTime(Date expireTime) { |
||||
this.expireTime = expireTime; |
||||
} |
||||
|
||||
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; |
||||
} |
||||
|
||||
public String getUserName() { |
||||
return userName; |
||||
} |
||||
|
||||
public void setUserName(String userName) { |
||||
this.userName = userName; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "AccessToken{" + |
||||
"id=" + id + |
||||
", userId=" + userId + |
||||
", userName='" + userName + '\'' + |
||||
", token='" + token + '\'' + |
||||
", expireTime=" + expireTime + |
||||
", createTime=" + createTime + |
||||
", updateTime=" + updateTime + |
||||
'}'; |
||||
} |
||||
} |
@ -0,0 +1,290 @@
|
||||
/* |
||||
* 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 cn.escheduler.common.enums.*; |
||||
|
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* command |
||||
*/ |
||||
public class ErrorCommand { |
||||
|
||||
/** |
||||
* id |
||||
*/ |
||||
private int id; |
||||
|
||||
/** |
||||
* command type |
||||
*/ |
||||
private CommandType commandType; |
||||
|
||||
/** |
||||
* process definition id |
||||
*/ |
||||
private int processDefinitionId; |
||||
|
||||
/** |
||||
* executor id |
||||
*/ |
||||
private int executorId; |
||||
|
||||
/** |
||||
* command parameter, format json |
||||
*/ |
||||
private String commandParam; |
||||
|
||||
/** |
||||
* task depend type |
||||
*/ |
||||
private TaskDependType taskDependType; |
||||
|
||||
/** |
||||
* failure strategy |
||||
*/ |
||||
private FailureStrategy failureStrategy; |
||||
|
||||
/** |
||||
* warning type |
||||
*/ |
||||
private WarningType warningType; |
||||
|
||||
/** |
||||
* warning group id |
||||
*/ |
||||
private Integer warningGroupId; |
||||
|
||||
/** |
||||
* schedule time |
||||
*/ |
||||
private Date scheduleTime; |
||||
|
||||
/** |
||||
* start time |
||||
*/ |
||||
private Date startTime; |
||||
|
||||
/** |
||||
* process instance priority |
||||
*/ |
||||
private Priority processInstancePriority; |
||||
|
||||
/** |
||||
* update time |
||||
*/ |
||||
private Date updateTime; |
||||
|
||||
/** |
||||
* 执行信息 |
||||
*/ |
||||
private String message; |
||||
|
||||
/** |
||||
* worker group id |
||||
*/ |
||||
private int workerGroupId; |
||||
|
||||
|
||||
public ErrorCommand(Command command, String message){ |
||||
this.commandType = command.getCommandType(); |
||||
this.executorId = command.getExecutorId(); |
||||
this.processDefinitionId = command.getProcessDefinitionId(); |
||||
this.commandParam = command.getCommandParam(); |
||||
this.warningType = command.getWarningType(); |
||||
this.warningGroupId = command.getWarningGroupId(); |
||||
this.scheduleTime = command.getScheduleTime(); |
||||
this.taskDependType = command.getTaskDependType(); |
||||
this.failureStrategy = command.getFailureStrategy(); |
||||
this.startTime = command.getStartTime(); |
||||
this.updateTime = command.getUpdateTime(); |
||||
this.processInstancePriority = command.getProcessInstancePriority(); |
||||
this.message = message; |
||||
} |
||||
|
||||
public ErrorCommand( |
||||
CommandType commandType, |
||||
TaskDependType taskDependType, |
||||
FailureStrategy failureStrategy, |
||||
int executorId, |
||||
int processDefinitionId, |
||||
String commandParam, |
||||
WarningType warningType, |
||||
int warningGroupId, |
||||
Date scheduleTime, |
||||
Priority processInstancePriority, |
||||
String message){ |
||||
this.commandType = commandType; |
||||
this.executorId = executorId; |
||||
this.processDefinitionId = processDefinitionId; |
||||
this.commandParam = commandParam; |
||||
this.warningType = warningType; |
||||
this.warningGroupId = warningGroupId; |
||||
this.scheduleTime = scheduleTime; |
||||
this.taskDependType = taskDependType; |
||||
this.failureStrategy = failureStrategy; |
||||
this.startTime = new Date(); |
||||
this.updateTime = new Date(); |
||||
this.processInstancePriority = processInstancePriority; |
||||
this.message = message; |
||||
} |
||||
|
||||
|
||||
public TaskDependType getTaskDependType() { |
||||
return taskDependType; |
||||
} |
||||
|
||||
public void setTaskDependType(TaskDependType taskDependType) { |
||||
this.taskDependType = taskDependType; |
||||
} |
||||
|
||||
public int getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(int id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public CommandType getCommandType() { |
||||
return commandType; |
||||
} |
||||
|
||||
public void setCommandType(CommandType commandType) { |
||||
this.commandType = commandType; |
||||
} |
||||
|
||||
public int getProcessDefinitionId() { |
||||
return processDefinitionId; |
||||
} |
||||
|
||||
public void setProcessDefinitionId(int processDefinitionId) { |
||||
this.processDefinitionId = processDefinitionId; |
||||
} |
||||
|
||||
|
||||
public FailureStrategy getFailureStrategy() { |
||||
return failureStrategy; |
||||
} |
||||
|
||||
public void setFailureStrategy(FailureStrategy failureStrategy) { |
||||
this.failureStrategy = failureStrategy; |
||||
} |
||||
|
||||
public void setCommandParam(String commandParam) { |
||||
this.commandParam = commandParam; |
||||
} |
||||
|
||||
public String getCommandParam() { |
||||
return commandParam; |
||||
} |
||||
|
||||
public WarningType getWarningType() { |
||||
return warningType; |
||||
} |
||||
|
||||
public void setWarningType(WarningType warningType) { |
||||
this.warningType = warningType; |
||||
} |
||||
|
||||
public Integer getWarningGroupId() { |
||||
return warningGroupId; |
||||
} |
||||
|
||||
public void setWarningGroupId(Integer warningGroupId) { |
||||
this.warningGroupId = warningGroupId; |
||||
} |
||||
|
||||
public Date getScheduleTime() { |
||||
return scheduleTime; |
||||
} |
||||
|
||||
public void setScheduleTime(Date scheduleTime) { |
||||
this.scheduleTime = scheduleTime; |
||||
} |
||||
|
||||
public Date getStartTime() { |
||||
return startTime; |
||||
} |
||||
|
||||
public void setStartTime(Date startTime) { |
||||
this.startTime = startTime; |
||||
} |
||||
|
||||
public int getExecutorId() { |
||||
return executorId; |
||||
} |
||||
|
||||
public void setExecutorId(int executorId) { |
||||
this.executorId = executorId; |
||||
} |
||||
|
||||
public Priority getProcessInstancePriority() { |
||||
return processInstancePriority; |
||||
} |
||||
|
||||
public void setProcessInstancePriority(Priority processInstancePriority) { |
||||
this.processInstancePriority = processInstancePriority; |
||||
} |
||||
|
||||
public Date getUpdateTime() { |
||||
return updateTime; |
||||
} |
||||
|
||||
public void setUpdateTime(Date updateTime) { |
||||
this.updateTime = updateTime; |
||||
} |
||||
|
||||
public int getWorkerGroupId() { |
||||
return workerGroupId; |
||||
} |
||||
|
||||
public void setWorkerGroupId(int workerGroupId) { |
||||
this.workerGroupId = workerGroupId; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "Command{" + |
||||
"id=" + id + |
||||
", commandType=" + commandType + |
||||
", processDefinitionId=" + processDefinitionId + |
||||
", executorId=" + executorId + |
||||
", commandParam='" + commandParam + '\'' + |
||||
", taskDependType=" + taskDependType + |
||||
", failureStrategy=" + failureStrategy + |
||||
", warningType=" + warningType + |
||||
", warningGroupId=" + warningGroupId + |
||||
", scheduleTime=" + scheduleTime + |
||||
", startTime=" + startTime + |
||||
", processInstancePriority=" + processInstancePriority + |
||||
", updateTime=" + updateTime + |
||||
", message=" + message + |
||||
'}'; |
||||
} |
||||
|
||||
public String getMessage() { |
||||
return message; |
||||
} |
||||
|
||||
public void setMessage(String message) { |
||||
this.message = message; |
||||
} |
||||
|
||||
|
||||
} |
@ -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,82 @@
|
||||
/* |
||||
* 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.upgrade; |
||||
|
||||
import cn.escheduler.common.utils.SchemaUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* upgrade manager |
||||
*/ |
||||
public class EschedulerManager { |
||||
private static final Logger logger = LoggerFactory.getLogger(EschedulerManager.class); |
||||
UpgradeDao upgradeDao = UpgradeDao.getInstance(); |
||||
|
||||
public void initEscheduler() { |
||||
this.initEschedulerSchema(); |
||||
} |
||||
|
||||
public void initEschedulerSchema() { |
||||
|
||||
logger.info("Start initializing the ark manager mysql table structure"); |
||||
upgradeDao.initEschedulerSchema(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* upgrade escheduler |
||||
*/ |
||||
public void upgradeEscheduler() throws Exception{ |
||||
|
||||
// Gets a list of all upgrades
|
||||
List<String> schemaList = SchemaUtils.getAllSchemaList(); |
||||
if(schemaList == null || schemaList.size() == 0) { |
||||
logger.info("There is no schema to upgrade!"); |
||||
}else { |
||||
|
||||
String version = ""; |
||||
// The target version of the upgrade
|
||||
String schemaVersion = ""; |
||||
for(String schemaDir : schemaList) { |
||||
// Gets the version of the current system
|
||||
if (upgradeDao.isExistsTable("t_escheduler_version")) { |
||||
version = upgradeDao.getCurrentVersion(); |
||||
}else { |
||||
version = "1.0.0"; |
||||
} |
||||
|
||||
schemaVersion = schemaDir.split("_")[0]; |
||||
if(SchemaUtils.isAGreatVersion(schemaVersion , version)) { |
||||
|
||||
logger.info("upgrade escheduler metadata version from " + version + " to " + schemaVersion); |
||||
|
||||
|
||||
logger.info("Begin upgrading escheduler's mysql table structure"); |
||||
upgradeDao.upgradeEscheduler(schemaDir); |
||||
|
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
// Assign the value of the version field in the version table to the version of the product
|
||||
upgradeDao.updateVersion(SchemaUtils.getSoftVersion()); |
||||
} |
||||
} |
@ -0,0 +1,299 @@
|
||||
/* |
||||
* 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.upgrade; |
||||
|
||||
import cn.escheduler.common.utils.MysqlUtil; |
||||
import cn.escheduler.common.utils.ScriptRunner; |
||||
import cn.escheduler.dao.AbstractBaseDao; |
||||
import cn.escheduler.dao.datasource.ConnectionFactory; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.io.*; |
||||
import java.sql.Connection; |
||||
import java.sql.PreparedStatement; |
||||
import java.sql.ResultSet; |
||||
import java.sql.SQLException; |
||||
|
||||
public class UpgradeDao extends AbstractBaseDao { |
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(UpgradeDao.class); |
||||
private static final String T_VERSION_NAME = "t_escheduler_version"; |
||||
|
||||
@Override |
||||
protected void init() { |
||||
|
||||
} |
||||
|
||||
private static class UpgradeDaoHolder { |
||||
private static final UpgradeDao INSTANCE = new UpgradeDao(); |
||||
} |
||||
|
||||
private UpgradeDao() { |
||||
} |
||||
|
||||
public static final UpgradeDao getInstance() { |
||||
return UpgradeDaoHolder.INSTANCE; |
||||
} |
||||
|
||||
|
||||
|
||||
public void initEschedulerSchema() { |
||||
|
||||
// Execute the escheduler DDL, it cannot be rolled back
|
||||
runInitEschedulerDDL(); |
||||
|
||||
// Execute the escheduler DML, it can be rolled back
|
||||
runInitEschedulerDML(); |
||||
|
||||
} |
||||
|
||||
private void runInitEschedulerDML() { |
||||
Connection conn = null; |
||||
try { |
||||
conn = ConnectionFactory.getDataSource().getConnection(); |
||||
conn.setAutoCommit(false); |
||||
// 执行escheduler_dml.sql脚本,导入escheduler相关的数据
|
||||
// Execute the ark_manager_dml.sql script to import the data related to escheduler
|
||||
|
||||
ScriptRunner initScriptRunner = new ScriptRunner(conn, false, true); |
||||
Reader initSqlReader = new FileReader(new File("sql/create/release-1.0.0_schema/mysql/escheduler_dml.sql")); |
||||
initScriptRunner.runScript(initSqlReader); |
||||
|
||||
conn.commit(); |
||||
} catch (IOException e) { |
||||
try { |
||||
conn.rollback(); |
||||
} catch (SQLException e1) { |
||||
logger.error(e1.getMessage(),e1); |
||||
} |
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException(e.getMessage(),e); |
||||
} catch (Exception e) { |
||||
try { |
||||
conn.rollback(); |
||||
} catch (SQLException e1) { |
||||
logger.error(e1.getMessage(),e1); |
||||
} |
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException(e.getMessage(),e); |
||||
} finally { |
||||
MysqlUtil.realeaseResource(null, null, conn); |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
private void runInitEschedulerDDL() { |
||||
Connection conn = null; |
||||
try { |
||||
conn = ConnectionFactory.getDataSource().getConnection(); |
||||
// Execute the escheduler_ddl.sql script to create the table structure of escheduler
|
||||
ScriptRunner initScriptRunner = new ScriptRunner(conn, true, true); |
||||
Reader initSqlReader = new FileReader(new File("sql/create/release-1.0.0_schema/mysql/escheduler_ddl.sql")); |
||||
initScriptRunner.runScript(initSqlReader); |
||||
|
||||
} catch (IOException e) { |
||||
|
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException(e.getMessage(),e); |
||||
} catch (Exception e) { |
||||
|
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException(e.getMessage(),e); |
||||
} finally { |
||||
MysqlUtil.realeaseResource(null, null, conn); |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
public boolean isExistsTable(String tableName) { |
||||
Connection conn = null; |
||||
try { |
||||
conn = ConnectionFactory.getDataSource().getConnection(); |
||||
ResultSet rs = conn.getMetaData().getTables(null, null, tableName, null); |
||||
if (rs.next()) { |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
|
||||
} catch (SQLException e) { |
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException(e.getMessage(),e); |
||||
} finally { |
||||
MysqlUtil.realeaseResource(null, null, conn); |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
public String getCurrentVersion() { |
||||
String sql = String.format("select version from %s",T_VERSION_NAME); |
||||
Connection conn = null; |
||||
ResultSet rs = null; |
||||
PreparedStatement pstmt = null; |
||||
String version = null; |
||||
try { |
||||
conn = ConnectionFactory.getDataSource().getConnection(); |
||||
pstmt = conn.prepareStatement(sql); |
||||
rs = pstmt.executeQuery(); |
||||
|
||||
if (rs.next()) { |
||||
version = rs.getString(1); |
||||
} |
||||
|
||||
return version; |
||||
|
||||
} catch (SQLException e) { |
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException("sql: " + sql, e); |
||||
} finally { |
||||
MysqlUtil.realeaseResource(rs, pstmt, conn); |
||||
|
||||
} |
||||
} |
||||
|
||||
|
||||
public void upgradeEscheduler(String schemaDir) { |
||||
|
||||
upgradeEschedulerDDL(schemaDir); |
||||
|
||||
upgradeEschedulerDML(schemaDir); |
||||
|
||||
} |
||||
|
||||
private void upgradeEschedulerDML(String schemaDir) { |
||||
String schemaVersion = schemaDir.split("_")[0]; |
||||
String mysqlSQLFilePath = "sql/upgrade/" + schemaDir + "/mysql/escheduler_dml.sql"; |
||||
Connection conn = null; |
||||
PreparedStatement pstmt = null; |
||||
try { |
||||
conn = ConnectionFactory.getDataSource().getConnection(); |
||||
conn.setAutoCommit(false); |
||||
// Execute the upgraded escheduler dml
|
||||
ScriptRunner scriptRunner = new ScriptRunner(conn, false, true); |
||||
Reader sqlReader = new FileReader(new File(mysqlSQLFilePath)); |
||||
scriptRunner.runScript(sqlReader); |
||||
if (isExistsTable(T_VERSION_NAME)) { |
||||
// Change version in the version table to the new version
|
||||
String upgradeSQL = String.format("update %s set version = ?",T_VERSION_NAME); |
||||
pstmt = conn.prepareStatement(upgradeSQL); |
||||
pstmt.setString(1, schemaVersion); |
||||
pstmt.executeUpdate(); |
||||
} |
||||
conn.commit(); |
||||
} catch (FileNotFoundException e) { |
||||
try { |
||||
conn.rollback(); |
||||
} catch (SQLException e1) { |
||||
logger.error(e1.getMessage(),e1); |
||||
} |
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException("sql file not found ", e); |
||||
} catch (IOException e) { |
||||
try { |
||||
conn.rollback(); |
||||
} catch (SQLException e1) { |
||||
logger.error(e1.getMessage(),e1); |
||||
} |
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException(e.getMessage(),e); |
||||
} catch (SQLException e) { |
||||
try { |
||||
conn.rollback(); |
||||
} catch (SQLException e1) { |
||||
logger.error(e1.getMessage(),e1); |
||||
} |
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException(e.getMessage(),e); |
||||
} catch (Exception e) { |
||||
try { |
||||
conn.rollback(); |
||||
} catch (SQLException e1) { |
||||
logger.error(e1.getMessage(),e1); |
||||
} |
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException(e.getMessage(),e); |
||||
} finally { |
||||
MysqlUtil.realeaseResource(null, pstmt, conn); |
||||
} |
||||
|
||||
} |
||||
|
||||
private void upgradeEschedulerDDL(String schemaDir) { |
||||
String mysqlSQLFilePath = "sql/upgrade/" + schemaDir + "/mysql/escheduler_ddl.sql"; |
||||
Connection conn = null; |
||||
PreparedStatement pstmt = null; |
||||
try { |
||||
conn = ConnectionFactory.getDataSource().getConnection(); |
||||
String dbName = conn.getCatalog(); |
||||
logger.info(dbName); |
||||
conn.setAutoCommit(true); |
||||
// Execute the escheduler ddl.sql for the upgrade
|
||||
ScriptRunner scriptRunner = new ScriptRunner(conn, true, true); |
||||
Reader sqlReader = new FileReader(new File(mysqlSQLFilePath)); |
||||
scriptRunner.runScript(sqlReader); |
||||
|
||||
} catch (FileNotFoundException e) { |
||||
|
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException("sql file not found ", e); |
||||
} catch (IOException e) { |
||||
|
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException(e.getMessage(),e); |
||||
} catch (SQLException e) { |
||||
|
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException(e.getMessage(),e); |
||||
} catch (Exception e) { |
||||
|
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException(e.getMessage(),e); |
||||
} finally { |
||||
MysqlUtil.realeaseResource(null, pstmt, conn); |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
public void updateVersion(String version) { |
||||
// Change version in the version table to the new version
|
||||
String upgradeSQL = String.format("update %s set version = ?",T_VERSION_NAME); |
||||
PreparedStatement pstmt = null; |
||||
Connection conn = null; |
||||
try { |
||||
conn = ConnectionFactory.getDataSource().getConnection(); |
||||
pstmt = conn.prepareStatement(upgradeSQL); |
||||
pstmt.setString(1, version); |
||||
pstmt.executeUpdate(); |
||||
|
||||
} catch (SQLException e) { |
||||
logger.error(e.getMessage(),e); |
||||
throw new RuntimeException("sql: " + upgradeSQL, e); |
||||
} finally { |
||||
MysqlUtil.realeaseResource(null, pstmt, conn); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,44 @@
|
||||
/* |
||||
* 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.upgrade.shell; |
||||
|
||||
import cn.escheduler.dao.upgrade.EschedulerManager; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
/** |
||||
* init escheduler |
||||
* |
||||
*/ |
||||
public class CreateEscheduler { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CreateEscheduler.class); |
||||
|
||||
public static void main(String[] args) { |
||||
Thread.currentThread().setName("manager-CreateEscheduler"); |
||||
EschedulerManager eschedulerManager = new EschedulerManager(); |
||||
eschedulerManager.initEscheduler(); |
||||
logger.info("init escheduler finished"); |
||||
try { |
||||
eschedulerManager.upgradeEscheduler(); |
||||
logger.info("upgrade escheduler finished"); |
||||
} catch (Exception e) { |
||||
logger.error("upgrade escheduler failed",e); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,38 @@
|
||||
/* |
||||
* 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.upgrade.shell; |
||||
|
||||
import cn.escheduler.dao.upgrade.EschedulerManager; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
/** |
||||
* init escheduler |
||||
* |
||||
*/ |
||||
public class InitEscheduler { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(InitEscheduler.class); |
||||
|
||||
public static void main(String[] args) { |
||||
Thread.currentThread().setName("manager-InitEscheduler"); |
||||
EschedulerManager eschedulerManager = new EschedulerManager(); |
||||
eschedulerManager.initEscheduler(); |
||||
logger.info("init escheduler finished"); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,47 @@
|
||||
/* |
||||
* 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.upgrade.shell; |
||||
|
||||
import cn.escheduler.dao.upgrade.EschedulerManager; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
/** |
||||
* upgrade escheduler database |
||||
*/ |
||||
public class UpgradeEscheduler { |
||||
private static final Logger logger = LoggerFactory.getLogger(UpgradeEscheduler.class); |
||||
|
||||
public static void main(String[] args) { |
||||
Thread.currentThread().setName("manager-UpgradeEscheduler"); |
||||
|
||||
EschedulerManager eschedulerManager = new EschedulerManager(); |
||||
try { |
||||
eschedulerManager.upgradeEscheduler(); |
||||
logger.info("upgrade escheduler finished"); |
||||
} catch (Exception e) { |
||||
logger.error(e.getMessage(),e); |
||||
logger.info("Upgrade escheduler failed"); |
||||
throw new RuntimeException(e); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,62 @@
|
||||
/* |
||||
* 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.common.utils.EncryptionUtils; |
||||
import cn.escheduler.dao.datasource.ConnectionFactory; |
||||
import cn.escheduler.dao.model.AccessToken; |
||||
import org.junit.Assert; |
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
|
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
|
||||
|
||||
public class AccessTokenMapperTest { |
||||
|
||||
|
||||
AccessTokenMapper accessTokenMapper; |
||||
|
||||
@Before |
||||
public void before(){ |
||||
accessTokenMapper = ConnectionFactory.getSqlSession().getMapper(AccessTokenMapper.class); |
||||
} |
||||
|
||||
@Test |
||||
public void testInsert(){ |
||||
AccessToken accessToken = new AccessToken(); |
||||
accessToken.setUserId(10); |
||||
accessToken.setExpireTime(new Date()); |
||||
accessToken.setToken("ssssssssssssssssssssssssss"); |
||||
accessToken.setCreateTime(new Date()); |
||||
accessToken.setUpdateTime(new Date()); |
||||
accessTokenMapper.insert(accessToken); |
||||
} |
||||
|
||||
@Test |
||||
public void testListPaging(){ |
||||
Integer count = accessTokenMapper.countAccessTokenPaging(1,""); |
||||
Assert.assertEquals(count, (Integer) 5); |
||||
|
||||
List<AccessToken> accessTokenList = accessTokenMapper.queryAccessTokenPaging(1,"", 0, 2); |
||||
Assert.assertEquals(accessTokenList.size(), 5); |
||||
} |
||||
|
||||
|
||||
} |
@ -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); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,65 @@
|
||||
package cn.escheduler.server.worker; |
||||
|
||||
import org.apache.commons.lang.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.io.BufferedReader; |
||||
import java.io.FileInputStream; |
||||
import java.io.IOException; |
||||
import java.io.InputStreamReader; |
||||
|
||||
/** |
||||
* Created by qiaozhanwei on 2019/4/15. |
||||
*/ |
||||
public class EnvFileTest { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(EnvFileTest.class); |
||||
|
||||
public static void main(String[] args) { |
||||
String path = System.getProperty("user.dir")+"\\script\\env\\.escheduler_env.sh"; |
||||
String pythonHome = getPythonHome(path); |
||||
logger.info(pythonHome); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* get python home |
||||
* @param path |
||||
* @return |
||||
*/ |
||||
private static String getPythonHome(String path){ |
||||
BufferedReader br = null; |
||||
String line = null; |
||||
StringBuilder sb = new StringBuilder(); |
||||
try { |
||||
br = new BufferedReader(new InputStreamReader(new FileInputStream(path))); |
||||
while ((line = br.readLine()) != null){ |
||||
if (line.contains("PYTHON_HOME")){ |
||||
sb.append(line); |
||||
break; |
||||
} |
||||
} |
||||
String result = sb.toString(); |
||||
if (StringUtils.isEmpty(result)){ |
||||
return null; |
||||
} |
||||
String[] arrs = result.split("="); |
||||
if (arrs.length == 2){ |
||||
return arrs[1]; |
||||
} |
||||
|
||||
}catch (IOException e){ |
||||
logger.error("read file failed : " + e.getMessage(),e); |
||||
}finally { |
||||
try { |
||||
if (br != null){ |
||||
br.close(); |
||||
} |
||||
} catch (IOException e) { |
||||
logger.error(e.getMessage(),e); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue