use of com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp in project Saturn by vipshop.
the class JobServiceImpl method updateJobCron.
@Transactional(rollbackFor = Exception.class)
@Override
public void updateJobCron(String namespace, String jobName, String cron, Map<String, String> customContext, String updatedBy) throws SaturnJobConsoleException {
String cron0 = cron;
if (cron0 != null && !cron0.trim().isEmpty()) {
try {
cron0 = cron0.trim();
CronExpression.validateExpression(cron0);
} catch (ParseException e) {
throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, "The cron expression is invalid: " + cron);
}
} else {
cron0 = "";
}
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
if (curatorFrameworkOp.checkExists(JobNodePath.getConfigNodePath(jobName))) {
String newCustomContextStr = null;
String oldCustomContextStr = curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_CUSTOM_CONTEXT));
Map<String, String> oldCustomContextMap = toCustomContext(oldCustomContextStr);
if (customContext != null && !customContext.isEmpty()) {
oldCustomContextMap.putAll(customContext);
newCustomContextStr = toCustomContext(oldCustomContextMap);
if (newCustomContextStr.length() > 8000) {
throw new SaturnJobConsoleException("The all customContext is out of db limit (Varchar[8000])");
}
if (newCustomContextStr.getBytes().length > 1024 * 1024) {
throw new SaturnJobConsoleException("The all customContext is out of zk limit memory(1M)");
}
}
String newCron = null;
String oldCron = curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_CRON));
if (cron0 != null && oldCron != null && !cron0.equals(oldCron.trim())) {
newCron = cron0;
}
if (newCustomContextStr != null || newCron != null) {
saveCronToDb(jobName, curatorFrameworkOp, newCustomContextStr, newCron, updatedBy);
}
if (newCustomContextStr != null) {
curatorFrameworkOp.update(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_CUSTOM_CONTEXT), newCustomContextStr);
}
if (newCron != null) {
curatorFrameworkOp.update(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_CRON), newCron);
}
} else {
throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "The job does not exists: " + jobName);
}
}
use of com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp in project Saturn by vipshop.
the class JobServiceImpl method getJobServersStatus.
@Override
public List<JobServerStatus> getJobServersStatus(String namespace, String jobName) throws SaturnJobConsoleException {
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
List<String> executors = getJobServerList(namespace, jobName);
List<JobServerStatus> result = new ArrayList<>();
if (executors != null && !executors.isEmpty()) {
for (String each : executors) {
result.add(getJobServerStatus(jobName, each, curatorFrameworkOp));
}
}
return result;
}
use of com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp in project Saturn by vipshop.
the class JobServiceImpl method addOrCopyJob.
private void addOrCopyJob(String namespace, JobConfig jobConfig, String jobNameCopied, String createdBy) throws SaturnJobConsoleException {
List<JobConfig> unSystemJobs = getUnSystemJobs(namespace);
Set<JobConfig> streamChangedJobs = new HashSet<>();
validateJobConfig(namespace, jobConfig, unSystemJobs, streamChangedJobs);
// 如果数据存在相同作业名,则抛异常
// 直接再查一次,不使用unSystemJobs,因为也不能与系统作业名相同
String jobName = jobConfig.getJobName();
if (currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName) != null) {
throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, String.format("该作业(%s)已经存在", jobName));
}
// 如果zk存在该作业,则尝试删除
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
if (curatorFrameworkOp.checkExists(JobNodePath.getJobNodePath(jobName))) {
if (!removeJobFromZk(jobName, curatorFrameworkOp)) {
throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, String.format("该作业(%s)正在删除中,请稍后再试", jobName));
}
}
// 该域作业总数不能超过一定数量
int maxJobNum = getMaxJobNum();
if (jobIncExceeds(namespace, maxJobNum, 1)) {
throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, String.format("总作业数超过最大限制(%d),作业名%s创建失败", maxJobNum, jobName));
}
// 如果是copy作业,则从数据库中复制被拷贝的作业的配置到新的作业配置
JobConfig myJobConfig = jobConfig;
if (jobNameCopied != null) {
myJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobNameCopied);
SaturnBeanUtils.copyPropertiesIgnoreNull(jobConfig, myJobConfig);
}
// 设置作业配置字段默认值,并且强制纠正某些字段
correctConfigValueWhenAddJob(myJobConfig);
// 添加该作业到数据库
currentJobConfigService.create(constructJobConfig4DB(namespace, myJobConfig, createdBy, createdBy));
// 更新关联作业的上下游
for (JobConfig streamChangedJob : streamChangedJobs) {
currentJobConfigService.updateStream(constructJobConfig4DB(namespace, streamChangedJob, null, createdBy));
}
// 添加该作业配置到zk,并联动更新关联作业的上下游
createJobConfigToZk(myJobConfig, streamChangedJobs, curatorFrameworkOp);
}
use of com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp in project Saturn by vipshop.
the class JobServiceImpl method disableJob.
@Transactional(rollbackFor = Exception.class)
@Override
public void disableJob(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 + ")已经处于禁用状态");
}
jobConfig.setEnabled(Boolean.FALSE);
jobConfig.setLastUpdateTime(new Date());
jobConfig.setLastUpdateBy(updatedBy);
currentJobConfigService.updateByPrimaryKey(jobConfig);
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
curatorFrameworkOp.update(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_ENABLED), false);
}
use of com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp in project Saturn by vipshop.
the class JobServiceImpl method getAllJobNamesFromZK.
@Override
public List<String> getAllJobNamesFromZK(String namespace) throws SaturnJobConsoleException {
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
String jobsNodePath = JobNodePath.get$JobsNodePath();
List<String> jobs = curatorFrameworkOp.getChildren(jobsNodePath);
if (jobs == null) {
return Lists.newArrayList();
}
List<String> allJobs = new ArrayList<>();
for (String job : jobs) {
// 如果config节点存在才视为正常作业,其他异常作业在其他功能操作时也忽略
if (curatorFrameworkOp.checkExists(JobNodePath.getConfigNodePath(job))) {
allJobs.add(job);
}
}
Collections.sort(allJobs);
return allJobs;
}
Aggregations