use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImpl method setPreferList.
@Transactional(rollbackFor = Exception.class)
@Override
public void setPreferList(String namespace, String jobName, String preferList, String updatedBy) throws SaturnJobConsoleException {
// save to db
JobConfig4DB oldJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
if (oldJobConfig == null) {
throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "设置该作业(" + jobName + ")优先Executor失败,因为该作业不存在");
}
// 启用状态的本地模式作业,不能设置preferList
Boolean enabled = oldJobConfig.getEnabled();
Boolean localMode = oldJobConfig.getLocalMode();
if (enabled != null && enabled && localMode != null && localMode) {
throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, String.format("启用状态的本地模式作业(%s),不能设置优先Executor,请先禁用它", jobName));
}
JobConfig4DB newJobConfig = new JobConfig4DB();
BeanUtils.copyProperties(oldJobConfig, newJobConfig);
newJobConfig.setPreferList(preferList);
currentJobConfigService.updateNewAndSaveOld2History(newJobConfig, oldJobConfig, updatedBy);
// save to zk
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
String jobConfigPreferListNodePath = SaturnExecutorsNode.getJobConfigPreferListNodePath(jobName);
curatorFrameworkOp.update(jobConfigPreferListNodePath, preferList);
// delete and create the forceShard node
String jobConfigForceShardNodePath = SaturnExecutorsNode.getJobConfigForceShardNodePath(jobName);
curatorFrameworkOp.delete(jobConfigForceShardNodePath);
curatorFrameworkOp.create(jobConfigForceShardNodePath);
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImpl method getCandidateExecutors.
@Override
public List<ExecutorProvided> getCandidateExecutors(String namespace, String jobName) throws SaturnJobConsoleException {
JobConfig4DB currentJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
if (currentJobConfig == null) {
throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "不能获取该作业(" + jobName + ")可选择的优先Executor,因为该作业不存在");
}
List<ExecutorProvided> executorProvidedList = new ArrayList<>();
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
String executorsNodePath = SaturnExecutorsNode.getExecutorsNodePath();
if (!curatorFrameworkOp.checkExists(executorsNodePath)) {
return executorProvidedList;
}
List<String> executors = curatorFrameworkOp.getChildren(executorsNodePath);
if (executors == null) {
executors = new ArrayList<>();
}
if (!executors.isEmpty()) {
for (String executor : executors) {
if (curatorFrameworkOp.checkExists(SaturnExecutorsNode.getExecutorTaskNodePath(executor))) {
// 过滤容器中的Executor,容器资源只需要可以选择taskId即可
continue;
}
ExecutorProvided executorProvided = new ExecutorProvided();
executorProvided.setType(ExecutorProvidedType.PHYSICAL);
executorProvided.setExecutorName(executor);
executorProvided.setNoTraffic(curatorFrameworkOp.checkExists(SaturnExecutorsNode.getExecutorNoTrafficNodePath(executor)));
String ip = curatorFrameworkOp.getData(SaturnExecutorsNode.getExecutorIpNodePath(executor));
if (StringUtils.isNotBlank(ip)) {
executorProvided.setStatus(ExecutorProvidedStatus.ONLINE);
executorProvided.setIp(ip);
} else {
executorProvided.setStatus(ExecutorProvidedStatus.OFFLINE);
}
executorProvidedList.add(executorProvided);
}
}
List<ExecutorProvided> dockerExecutorProvided = getContainerTaskIds(curatorFrameworkOp);
executorProvidedList.addAll(dockerExecutorProvided);
if (StringUtils.isBlank(jobName)) {
return executorProvidedList;
}
String preferListNodePath = JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_PREFER_LIST);
if (!curatorFrameworkOp.checkExists(preferListNodePath)) {
return executorProvidedList;
}
String preferList = curatorFrameworkOp.getData(preferListNodePath);
if (Strings.isNullOrEmpty(preferList)) {
return executorProvidedList;
}
handlerPreferListString(curatorFrameworkOp, preferList, executors, dockerExecutorProvided, executorProvidedList);
return executorProvidedList;
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImpl method enableJob.
@Transactional(rollbackFor = Exception.class)
@Override
public void enableJob(String namespace, String jobName, String updatedBy) throws SaturnJobConsoleException {
JobConfig4DB jobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
if (jobConfig == null) {
throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "不能启用该作业(" + jobName + "),因为该作业不存在");
}
if (jobConfig.getEnabled()) {
throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, "该作业(" + jobName + ")已经处于启用状态");
}
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
boolean allShardsFinished = isAllShardsFinished(jobName, curatorFrameworkOp);
if (!allShardsFinished) {
throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, "不能启用该作业(" + jobName + "),因为该作业不处于STOPPED状态");
}
jobConfig.setEnabled(true);
jobConfig.setLastUpdateTime(new Date());
jobConfig.setLastUpdateBy(updatedBy);
currentJobConfigService.updateByPrimaryKey(jobConfig);
curatorFrameworkOp.update(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_ENABLED), true);
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImpl method getJobConfigByStatusWithCondition.
private List<JobConfig4DB> getJobConfigByStatusWithCondition(String namespace, Map<String, Object> condition, int page, int size) throws SaturnJobConsoleException {
JobStatus jobStatus = (JobStatus) condition.get("jobStatus");
if (jobStatus == null) {
return currentJobConfigService.findConfigsByNamespaceWithCondition(namespace, condition, PageableUtil.generatePageble(page, size));
}
List<JobConfig4DB> jobConfig4DBList = new ArrayList<>();
List<JobConfig4DB> enabledJobConfigList = currentJobConfigService.findConfigsByNamespaceWithCondition(namespace, condition, null);
for (JobConfig4DB jobConfig4DB : enabledJobConfigList) {
JobStatus currentJobStatus = getJobStatus(namespace, jobConfig4DB.getJobName());
if (jobStatus.equals(currentJobStatus)) {
jobConfig4DBList.add(jobConfig4DB);
}
}
return jobConfig4DBList;
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImpl method removeJob.
@Transactional(rollbackFor = Exception.class)
@Override
public void removeJob(String namespace, String jobName) throws SaturnJobConsoleException {
JobConfig4DB jobConfig4DB = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
if (jobConfig4DB == null) {
throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "不能删除该作业(" + jobName + "),因为该作业不存在");
}
String upStream = jobConfig4DB.getUpStream();
if (StringUtils.isNotBlank(upStream)) {
throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "不能删除该作业(" + jobName + "),因为该作业存在上游作业(" + upStream + "),请先断开上下游关系再删除");
}
String downStream = jobConfig4DB.getDownStream();
if (StringUtils.isNotBlank(downStream)) {
throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "不能删除该作业(" + jobName + "),因为该作业存在下游作业(" + downStream + "),请先断开上下游关系再删除");
}
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
JobStatus jobStatus = getJobStatus(jobName, curatorFrameworkOp, jobConfig4DB.getEnabled());
if (JobStatus.STOPPED != jobStatus) {
throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, String.format("不能删除该作业(%s),因为该作业不处于STOPPED状态", jobName));
}
Stat stat = curatorFrameworkOp.getStat(JobNodePath.getJobNodePath(jobName));
if (stat != null) {
long createTimeDiff = System.currentTimeMillis() - stat.getCtime();
if (createTimeDiff < SaturnConstants.JOB_CAN_BE_DELETE_TIME_LIMIT) {
throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, String.format("不能删除该作业(%s),因为该作业创建时间距离现在不超过%d分钟", jobName, SaturnConstants.JOB_CAN_BE_DELETE_TIME_LIMIT / 60000));
}
}
// remove job from db
currentJobConfigService.deleteByPrimaryKey(jobConfig4DB.getId());
// remove job from zk
removeJobFromZk(jobName, curatorFrameworkOp);
}
Aggregations