Java Code Examples for com.xxl.job.core.biz.model.ReturnT#FAIL

The following examples show how to use com.xxl.job.core.biz.model.ReturnT#FAIL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XxlJobServiceImpl.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnT<String> remove(Integer id) {
    XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
    String group = String.valueOf(xxlJobInfo.getJobGroup());
    String name = String.valueOf(xxlJobInfo.getId());

    try {
        // unbind quartz
        XxlJobDynamicScheduler.removeJob(name, group);

        xxlJobInfoDao.delete(id);
        xxlJobLogDao.delete(id);
        xxlJobLogGlueDao.deleteByJobId(id);
        return ReturnT.SUCCESS;
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        return ReturnT.FAIL;
    }
}
 
Example 2
Source File: JobGroupController.java    From xxl-job with GNU General Public License v3.0 6 votes vote down vote up
@RequestMapping("/remove")
@ResponseBody
public ReturnT<String> remove(int id){

	// valid
	int count = xxlJobInfoDao.pageListCount(0, 10, id, -1,  null, null, null);
	if (count > 0) {
		return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_0") );
	}

	List<XxlJobGroup> allList = xxlJobGroupDao.findAll();
	if (allList.size() == 1) {
		return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_1") );
	}

	int ret = xxlJobGroupDao.remove(id);
	return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
}
 
Example 3
Source File: JobGroupController.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/remove")
@ResponseBody
public ReturnT<String> remove(Integer id, Integer type) {

    // valid
    int count = xxlJobInfoDao.pageListCount(0, 10, id, null, null, type);
    if (count > 0) {
        return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_0"));
    }

    List<XxlJobGroup> allList = xxlJobGroupDao.findAll();
    if (allList.size() == 1) {
        return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_1"));
    }

    int ret = xxlJobGroupDao.remove(id);
    return (ret > 0) ? ReturnT.SUCCESS : ReturnT.FAIL;
}
 
Example 4
Source File: XxlJobServiceImpl.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnT<String> remove(int id) {
	XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
       String group = String.valueOf(xxlJobInfo.getJobGroup());
       String name = String.valueOf(xxlJobInfo.getId());

	try {
		XxlJobDynamicScheduler.removeJob(name, group);
		xxlJobInfoDao.delete(id);
		xxlJobLogDao.delete(id);
		xxlJobLogGlueDao.deleteByJobId(id);
		return ReturnT.SUCCESS;
	} catch (SchedulerException e) {
		logger.error(e.getMessage(), e);
	}
	return ReturnT.FAIL;
}
 
Example 5
Source File: JobGroupController.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/remove")
@ResponseBody
public ReturnT<String> remove(Integer id, Integer type) {

    // valid
    int count = xxlJobInfoDao.pageListCount(0, 10, id, null, null, type);
    if (count > 0) {
        return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_0"));
    }

    List<XxlJobGroup> allList = xxlJobGroupDao.findAll();
    if (allList.size() == 1) {
        return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_1"));
    }

    int ret = xxlJobGroupDao.remove(id);
    return (ret > 0) ? ReturnT.SUCCESS : ReturnT.FAIL;
}
 
Example 6
Source File: JobGroupController.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/remove")
@ResponseBody
public ReturnT<String> remove(int id){

	// valid
	int count = xxlJobInfoDao.pageListCount(0, 10, id, null, null);
	if (count > 0) {
		return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_0") );
	}

	List<XxlJobGroup> allList = xxlJobGroupDao.findAll();
	if (allList.size() == 1) {
		return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_1") );
	}

	int ret = xxlJobGroupDao.remove(id);
	return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
}
 
Example 7
Source File: JobGroupController.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/update")
@ResponseBody
public ReturnT<String> update(XxlJobGroup xxlJobGroup){
	// valid
	if (xxlJobGroup.getAppName()==null || StringUtils.isBlank(xxlJobGroup.getAppName())) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input")+"AppName") );
	}
	if (xxlJobGroup.getAppName().length()<4 || xxlJobGroup.getAppName().length()>64) {
		return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_appName_length") );
	}
	if (xxlJobGroup.getTitle()==null || StringUtils.isBlank(xxlJobGroup.getTitle())) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")) );
	}
	if (xxlJobGroup.getAddressType()!=0) {
		if (StringUtils.isBlank(xxlJobGroup.getAddressList())) {
			return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
		}
		String[] addresss = xxlJobGroup.getAddressList().split(",");
		for (String item: addresss) {
			if (StringUtils.isBlank(item)) {
				return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
			}
		}
	}

	int ret = xxlJobGroupDao.update(xxlJobGroup);
	return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
}
 
Example 8
Source File: XxlJobServiceImpl.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> stop(Integer id) {
    XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
    String group = String.valueOf(xxlJobInfo.getJobGroup());
    String name = String.valueOf(xxlJobInfo.getId());

    try {
        // bind quartz
        boolean ret = XxlJobDynamicScheduler.removeJob(name, group);
        return ret ? ReturnT.SUCCESS : ReturnT.FAIL;
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        return ReturnT.FAIL;
    }
}
 
Example 9
Source File: JobGroupController.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/save")
@ResponseBody
public ReturnT<String> save(XxlJobGroup xxlJobGroup) {

    // valid
    if (xxlJobGroup.getAppName() == null || StringUtils.isBlank(xxlJobGroup.getAppName())) {
        return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + "AppName"));
    }
    if (xxlJobGroup.getAppName().length() < 4 || xxlJobGroup.getAppName().length() > 64) {
        return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_appName_length"));
    }
    if (xxlJobGroup.getTitle() == null || StringUtils.isBlank(xxlJobGroup.getTitle())) {
        return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")));
    }
    if (xxlJobGroup.getAddressType() != 0) {
        if (StringUtils.isBlank(xxlJobGroup.getAddressList())) {
            return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_addressType_limit"));
        }
        String[] addresss = xxlJobGroup.getAddressList().split(",");
        for (String item : addresss) {
            if (StringUtils.isBlank(item)) {
                return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid"));
            }
        }
    }

    int ret = xxlJobGroupDao.save(xxlJobGroup);
    return (ret > 0) ? ReturnT.SUCCESS : ReturnT.FAIL;
}
 
Example 10
Source File: XxlJobServiceImpl.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> stop(int id) {
       XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
       String group = String.valueOf(xxlJobInfo.getJobGroup());
       String name = String.valueOf(xxlJobInfo.getId());

	try {
		// bind quartz
           boolean ret = XxlJobDynamicScheduler.removeJob(name, group);
           return ret?ReturnT.SUCCESS:ReturnT.FAIL;
	} catch (SchedulerException e) {
		logger.error(e.getMessage(), e);
		return ReturnT.FAIL;
	}
}
 
Example 11
Source File: XxlJobServiceImpl.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> start(int id) {
	XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
	String group = String.valueOf(xxlJobInfo.getJobGroup());
	String name = String.valueOf(xxlJobInfo.getId());
	String cronExpression = xxlJobInfo.getJobCron();

	try {
		boolean ret = XxlJobDynamicScheduler.addJob(name, group, cronExpression);
		return ret?ReturnT.SUCCESS:ReturnT.FAIL;
	} catch (SchedulerException e) {
		logger.error(e.getMessage(), e);
		return ReturnT.FAIL;
	}
}
 
Example 12
Source File: XxlJobServiceImpl.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> start(Integer id) {
    XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
    if (JobTypeEnum.CRON.eq(xxlJobInfo.getType())) {
        if (!CronExpression.isValidExpression(xxlJobInfo.getJobCron())) {
            return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid"));
        }
    } else {
        //表单校验
        String msg = validate(xxlJobInfo.getIntervalSeconds(), xxlJobInfo.getRepeatCount(),
                xxlJobInfo.getStartExecuteTime(), xxlJobInfo.getEndExecuteTime());
        if (!StringUtils.isEmpty(msg)) {
            return new ReturnT<String>(ReturnT.FAIL_CODE, msg);
        }
    }
    String group = String.valueOf(xxlJobInfo.getJobGroup());
    String name = String.valueOf(xxlJobInfo.getId());
    String cronExpression = xxlJobInfo.getJobCron();
    boolean ret = false;
    try {
        //判断定时类型
        if (JobTypeEnum.CRON.eq(xxlJobInfo.getType())) {
            ret = XxlJobDynamicScheduler.addJob(name, group, cronExpression);
        } else {
            /*if (!DateUtil.isMatch(xxlJobInfo.get())) {
                return new ReturnT<>(ReturnT.START_JOB_FAI, "触发时间不能小于当前时间.");
            }*/
            ret = XxlJobDynamicScheduler.addJob(name, group, xxlJobInfo.getStartExecuteTime(), xxlJobInfo.getEndExecuteTime(), xxlJobInfo.getIntervalSeconds(), xxlJobInfo.getRepeatCount());
        }
        return ret ? ReturnT.SUCCESS : ReturnT.FAIL;
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        return ReturnT.FAIL;
    }
}
 
Example 13
Source File: JobGroupController.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping("/save")
@ResponseBody
public ReturnT<String> save(XxlJobGroup xxlJobGroup){

	// valid
	if (xxlJobGroup.getAppname()==null || xxlJobGroup.getAppname().trim().length()==0) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input")+"AppName") );
	}
	if (xxlJobGroup.getAppname().length()<4 || xxlJobGroup.getAppname().length()>64) {
		return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_appname_length") );
	}
	if (xxlJobGroup.getTitle()==null || xxlJobGroup.getTitle().trim().length()==0) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")) );
	}
	if (xxlJobGroup.getAddressType()!=0) {
		if (xxlJobGroup.getAddressList()==null || xxlJobGroup.getAddressList().trim().length()==0) {
			return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
		}
		String[] addresss = xxlJobGroup.getAddressList().split(",");
		for (String item: addresss) {
			if (item==null || item.trim().length()==0) {
				return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
			}
		}
	}

	int ret = xxlJobGroupDao.save(xxlJobGroup);
	return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
}
 
Example 14
Source File: JobGroupController.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/save")
@ResponseBody
public ReturnT<String> save(XxlJobGroup xxlJobGroup){

	// valid
	if (xxlJobGroup.getAppName()==null || StringUtils.isBlank(xxlJobGroup.getAppName())) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input")+"AppName") );
	}
	if (xxlJobGroup.getAppName().length()<4 || xxlJobGroup.getAppName().length()>64) {
		return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_appName_length") );
	}
	if (xxlJobGroup.getTitle()==null || StringUtils.isBlank(xxlJobGroup.getTitle())) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")) );
	}
	if (xxlJobGroup.getAddressType()!=0) {
		if (StringUtils.isBlank(xxlJobGroup.getAddressList())) {
			return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
		}
		String[] addresss = xxlJobGroup.getAddressList().split(",");
		for (String item: addresss) {
			if (StringUtils.isBlank(item)) {
				return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
			}
		}
	}

	int ret = xxlJobGroupDao.save(xxlJobGroup);
	return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
}
 
Example 15
Source File: XxlJobServiceImpl.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> stop(Integer id) {
    XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
    String group = String.valueOf(xxlJobInfo.getJobGroup());
    String name = String.valueOf(xxlJobInfo.getId());

    try {
        // bind quartz
        boolean ret = XxlJobDynamicScheduler.removeJob(name, group);
        return ret ? ReturnT.SUCCESS : ReturnT.FAIL;
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        return ReturnT.FAIL;
    }
}
 
Example 16
Source File: XxlJobServiceImpl.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> pause(int id) {
       XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
       String group = String.valueOf(xxlJobInfo.getJobGroup());
       String name = String.valueOf(xxlJobInfo.getId());

	try {
           boolean ret = XxlJobDynamicScheduler.pauseJob(name, group);	// jobStatus do not store
           return ret?ReturnT.SUCCESS:ReturnT.FAIL;
	} catch (SchedulerException e) {
		logger.error(e.getMessage(), e);
		return ReturnT.FAIL;
	}
}
 
Example 17
Source File: JobGroupController.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/save")
@ResponseBody
public ReturnT<String> save(XxlJobGroup xxlJobGroup){

	// valid
	if (xxlJobGroup.getAppName()==null || StringUtils.isBlank(xxlJobGroup.getAppName())) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input")+"AppName") );
	}
	if (xxlJobGroup.getAppName().length()<4 || xxlJobGroup.getAppName().length()>64) {
		return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_appName_length") );
	}
	if (xxlJobGroup.getTitle()==null || StringUtils.isBlank(xxlJobGroup.getTitle())) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")) );
	}
	if (xxlJobGroup.getAddressType()!=0) {
		if (StringUtils.isBlank(xxlJobGroup.getAddressList())) {
			return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
		}
		String[] addresss = xxlJobGroup.getAddressList().split(",");
		for (String item: addresss) {
			if (StringUtils.isBlank(item)) {
				return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
			}
		}
	}

	int ret = xxlJobGroupDao.save(xxlJobGroup);
	return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
}
 
Example 18
Source File: XxlJobServiceImpl.java    From open-capacity-platform with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnT<String> update(XxlJobInfo jobInfo) {

	// valid
	if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
		return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid") );
	}
	if (StringUtils.isBlank(jobInfo.getJobDesc())) {
		return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) );
	}
	if (StringUtils.isBlank(jobInfo.getAuthor())) {
		return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_author")) );
	}
	if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
		return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString("system_unvalid")) );
	}
	if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
		return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) );
	}
	if (ExecutorFailStrategyEnum.match(jobInfo.getExecutorFailStrategy(), null) == null) {
		return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorFailStrategy")+I18nUtil.getString("system_unvalid")));
	}

	// ChildJobId valid
	if (StringUtils.isNotBlank(jobInfo.getChildJobId())) {
		String[] childJobIds = StringUtils.split(jobInfo.getChildJobId(), ",");
		for (String childJobIdItem: childJobIds) {
			if (StringUtils.isNotBlank(childJobIdItem) && StringUtils.isNumeric(childJobIdItem)) {
				XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.valueOf(childJobIdItem));
				if (childJobInfo==null) {
					return new ReturnT<String>(ReturnT.FAIL_CODE,
							MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_not_found")), childJobIdItem));
				}
				// avoid cycle relate
				if (childJobInfo.getId() == jobInfo.getId()) {
					return new ReturnT<String>(ReturnT.FAIL_CODE, MessageFormat.format(I18nUtil.getString("jobinfo_field_childJobId_limit"), childJobIdItem));
				}
			} else {
				return new ReturnT<String>(ReturnT.FAIL_CODE,
						MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_unvalid")), childJobIdItem));
			}
		}
		jobInfo.setChildJobId(StringUtils.join(childJobIds, ","));
	}

	// stage job info
	XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(jobInfo.getId());
	if (exists_jobInfo == null) {
		return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString("system_not_found")) );
	}
	//String old_cron = exists_jobInfo.getJobCron();

	exists_jobInfo.setJobCron(jobInfo.getJobCron());
	exists_jobInfo.setJobDesc(jobInfo.getJobDesc());
	exists_jobInfo.setAuthor(jobInfo.getAuthor());
	exists_jobInfo.setAlarmEmail(jobInfo.getAlarmEmail());
	exists_jobInfo.setExecutorRouteStrategy(jobInfo.getExecutorRouteStrategy());
	exists_jobInfo.setExecutorHandler(jobInfo.getExecutorHandler());
	exists_jobInfo.setExecutorParam(jobInfo.getExecutorParam());
	exists_jobInfo.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy());
	exists_jobInfo.setExecutorFailStrategy(jobInfo.getExecutorFailStrategy());
	exists_jobInfo.setChildJobId(jobInfo.getChildJobId());
       xxlJobInfoDao.update(exists_jobInfo);

	// fresh quartz
	String qz_group = String.valueOf(exists_jobInfo.getJobGroup());
	String qz_name = String.valueOf(exists_jobInfo.getId());
       try {
           boolean ret = XxlJobDynamicScheduler.rescheduleJob(qz_group, qz_name, exists_jobInfo.getJobCron());
           return ret?ReturnT.SUCCESS:ReturnT.FAIL;
       } catch (SchedulerException e) {
           logger.error(e.getMessage(), e);
       }

	return ReturnT.FAIL;
}
 
Example 19
Source File: XxlJobServiceImpl.java    From zuihou-admin-boot with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnT<String> update(XxlJobInfo jobInfo) {

    // valid
    if (JobTypeEnum.CRON.eq(jobInfo.getType())) {
        if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
            return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid"));
        }
    } else {
        //表单校验
        String msg = validate(jobInfo.getIntervalSeconds(), jobInfo.getRepeatCount(),
                jobInfo.getStartExecuteTime(), jobInfo.getEndExecuteTime());
        if (!StringUtils.isEmpty(msg)) {
            return new ReturnT<String>(ReturnT.FAIL_CODE, msg);
        }
    }
    if (StringUtils.isBlank(jobInfo.getJobDesc())) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_field_jobdesc")));
    }
    if (StringUtils.isBlank(jobInfo.getAuthor())) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_field_author")));
    }
    if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy") + I18nUtil.getString("system_unvalid")));
    }
    if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy") + I18nUtil.getString("system_unvalid")));
    }

    // ChildJobId valid
    if (StringUtils.isNotBlank(jobInfo.getChildJobId())) {
        String[] childJobIds = StringUtils.split(jobInfo.getChildJobId(), ",");
        for (String childJobIdItem : childJobIds) {
            if (StringUtils.isNotBlank(childJobIdItem) && StringUtils.isNumeric(childJobIdItem)) {
                XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.valueOf(childJobIdItem));
                if (childJobInfo == null) {
                    return new ReturnT<String>(ReturnT.FAIL_CODE,
                            MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId") + "({0})" + I18nUtil.getString("system_not_found")), childJobIdItem));
                }
            } else {
                return new ReturnT<String>(ReturnT.FAIL_CODE,
                        MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId") + "({0})" + I18nUtil.getString("system_unvalid")), childJobIdItem));
            }
        }
        jobInfo.setChildJobId(StringUtils.join(childJobIds, ","));
    }

    // stage job info
    XxlJobInfo existsJobInfo = xxlJobInfoDao.loadById(jobInfo.getId());
    if (existsJobInfo == null) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id") + I18nUtil.getString("system_not_found")));
    }
    //String old_cron = exists_jobInfo.getJobCron();

    existsJobInfo.setJobCron(jobInfo.getJobCron());
    existsJobInfo.setJobDesc(jobInfo.getJobDesc());
    existsJobInfo.setAuthor(jobInfo.getAuthor());
    existsJobInfo.setAlarmEmail(jobInfo.getAlarmEmail());
    existsJobInfo.setExecutorRouteStrategy(jobInfo.getExecutorRouteStrategy());
    existsJobInfo.setExecutorHandler(jobInfo.getExecutorHandler());
    existsJobInfo.setExecutorParam(jobInfo.getExecutorParam());
    existsJobInfo.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy());
    existsJobInfo.setExecutorTimeout(jobInfo.getExecutorTimeout());
    existsJobInfo.setExecutorFailRetryCount(jobInfo.getExecutorFailRetryCount());
    existsJobInfo.setChildJobId(jobInfo.getChildJobId());
    existsJobInfo.setRepeatCount(jobInfo.getRepeatCount());
    existsJobInfo.setStartExecuteTime(jobInfo.getStartExecuteTime());
    existsJobInfo.setEndExecuteTime(jobInfo.getEndExecuteTime());
    existsJobInfo.setIntervalSeconds(jobInfo.getIntervalSeconds());
    xxlJobInfoDao.update(existsJobInfo);

    if (JobTypeEnum.TIMES.eq(jobInfo.getType())) {
        return ReturnT.SUCCESS;
    }

    // update quartz-cron if started
    String qzGroup = String.valueOf(existsJobInfo.getJobGroup());
    String qzName = String.valueOf(existsJobInfo.getId());
    try {
        XxlJobDynamicScheduler.updateJobCron(qzGroup, qzName, existsJobInfo.getJobCron());
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        return ReturnT.FAIL;
    }

    return ReturnT.SUCCESS;
}
 
Example 20
Source File: XxlJobServiceImpl.java    From zuihou-admin-cloud with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnT<String> update(XxlJobInfo jobInfo) {

    // valid
    if (JobTypeEnum.CRON.eq(jobInfo.getType())) {
        if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
            return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid"));
        }
    } else {
        //表单校验
        String msg = validate(jobInfo.getIntervalSeconds(), jobInfo.getRepeatCount(),
                jobInfo.getStartExecuteTime(), jobInfo.getEndExecuteTime());
        if (!StringUtils.isEmpty(msg)) {
            return new ReturnT<String>(ReturnT.FAIL_CODE, msg);
        }
    }
    if (StringUtils.isBlank(jobInfo.getJobDesc())) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_field_jobdesc")));
    }
    if (StringUtils.isBlank(jobInfo.getAuthor())) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_field_author")));
    }
    if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy") + I18nUtil.getString("system_unvalid")));
    }
    if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy") + I18nUtil.getString("system_unvalid")));
    }

    // ChildJobId valid
    if (StringUtils.isNotBlank(jobInfo.getChildJobId())) {
        String[] childJobIds = StringUtils.split(jobInfo.getChildJobId(), ",");
        for (String childJobIdItem : childJobIds) {
            if (StringUtils.isNotBlank(childJobIdItem) && StringUtils.isNumeric(childJobIdItem)) {
                XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.valueOf(childJobIdItem));
                if (childJobInfo == null) {
                    return new ReturnT<String>(ReturnT.FAIL_CODE,
                            MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId") + "({0})" + I18nUtil.getString("system_not_found")), childJobIdItem));
                }
            } else {
                return new ReturnT<String>(ReturnT.FAIL_CODE,
                        MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId") + "({0})" + I18nUtil.getString("system_unvalid")), childJobIdItem));
            }
        }
        jobInfo.setChildJobId(StringUtils.join(childJobIds, ","));
    }

    // stage job info
    XxlJobInfo existsJobInfo = xxlJobInfoDao.loadById(jobInfo.getId());
    if (existsJobInfo == null) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id") + I18nUtil.getString("system_not_found")));
    }
    //String old_cron = exists_jobInfo.getJobCron();

    existsJobInfo.setJobCron(jobInfo.getJobCron());
    existsJobInfo.setJobDesc(jobInfo.getJobDesc());
    existsJobInfo.setAuthor(jobInfo.getAuthor());
    existsJobInfo.setAlarmEmail(jobInfo.getAlarmEmail());
    existsJobInfo.setExecutorRouteStrategy(jobInfo.getExecutorRouteStrategy());
    existsJobInfo.setExecutorHandler(jobInfo.getExecutorHandler());
    existsJobInfo.setExecutorParam(jobInfo.getExecutorParam());
    existsJobInfo.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy());
    existsJobInfo.setExecutorTimeout(jobInfo.getExecutorTimeout());
    existsJobInfo.setExecutorFailRetryCount(jobInfo.getExecutorFailRetryCount());
    existsJobInfo.setChildJobId(jobInfo.getChildJobId());
    existsJobInfo.setRepeatCount(jobInfo.getRepeatCount());
    existsJobInfo.setStartExecuteTime(jobInfo.getStartExecuteTime());
    existsJobInfo.setEndExecuteTime(jobInfo.getEndExecuteTime());
    existsJobInfo.setIntervalSeconds(jobInfo.getIntervalSeconds());
    xxlJobInfoDao.update(existsJobInfo);

    if (JobTypeEnum.TIMES.eq(jobInfo.getType())) {
        return ReturnT.SUCCESS;
    }

    // update quartz-cron if started
    String qzGroup = String.valueOf(existsJobInfo.getJobGroup());
    String qzName = String.valueOf(existsJobInfo.getId());
    try {
        XxlJobDynamicScheduler.updateJobCron(qzGroup, qzName, existsJobInfo.getJobCron());
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        return ReturnT.FAIL;
    }

    return ReturnT.SUCCESS;
}