Search in sources :

Example 6 with XxlJobGroup

use of com.xxl.job.admin.core.model.XxlJobGroup in project xxl-job by xuxueli.

the class XxlJobGroupDaoTest method test.

@Test
public void test() {
    List<XxlJobGroup> list = xxlJobGroupDao.findAll();
    List<XxlJobGroup> list2 = xxlJobGroupDao.findByAddressType(0);
    XxlJobGroup group = new XxlJobGroup();
    group.setAppName("setAppName");
    group.setTitle("setTitle");
    group.setOrder(1);
    group.setAddressType(0);
    group.setAddressList("setAddressList");
    int ret = xxlJobGroupDao.save(group);
    XxlJobGroup group2 = xxlJobGroupDao.load(group.getId());
    group2.setAppName("setAppName2");
    group2.setTitle("setTitle2");
    group2.setOrder(2);
    group2.setAddressType(2);
    group2.setAddressList("setAddressList2");
    int ret2 = xxlJobGroupDao.update(group2);
    int ret3 = xxlJobGroupDao.remove(group.getId());
}
Also used : XxlJobGroup(com.xxl.job.admin.core.model.XxlJobGroup) Test(org.junit.Test)

Example 7 with XxlJobGroup

use of com.xxl.job.admin.core.model.XxlJobGroup in project xxl-job by xuxueli.

the class XxlJobServiceImpl method add.

@Override
public ReturnT<String> add(XxlJobInfo jobInfo) {
    // valid
    XxlJobGroup group = xxlJobGroupDao.load(jobInfo.getJobGroup());
    if (group == null) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_choose") + I18nUtil.getString("jobinfo_field_jobgroup")));
    }
    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")));
    }
    if (GlueTypeEnum.match(jobInfo.getGlueType()) == null) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_gluetype") + I18nUtil.getString("system_unvalid")));
    }
    if (GlueTypeEnum.BEAN == GlueTypeEnum.match(jobInfo.getGlueType()) && StringUtils.isBlank(jobInfo.getExecutorHandler())) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input") + "JobHandler"));
    }
    // fix "\r" in shell
    if (GlueTypeEnum.GLUE_SHELL == GlueTypeEnum.match(jobInfo.getGlueType()) && jobInfo.getGlueSource() != null) {
        jobInfo.setGlueSource(jobInfo.getGlueSource().replaceAll("\r", ""));
    }
    // 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, ","));
    }
    // add in db
    xxlJobInfoDao.save(jobInfo);
    if (jobInfo.getId() < 1) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_add") + I18nUtil.getString("system_fail")));
    }
    // add in quartz
    String qz_group = String.valueOf(jobInfo.getJobGroup());
    String qz_name = String.valueOf(jobInfo.getId());
    try {
        XxlJobDynamicScheduler.addJob(qz_name, qz_group, jobInfo.getJobCron());
        // XxlJobDynamicScheduler.pauseJob(qz_name, qz_group);
        return ReturnT.SUCCESS;
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        try {
            xxlJobInfoDao.delete(jobInfo.getId());
            XxlJobDynamicScheduler.removeJob(qz_name, qz_group);
        } catch (SchedulerException e1) {
            logger.error(e.getMessage(), e1);
        }
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_add") + I18nUtil.getString("system_fail")) + ":" + e.getMessage());
    }
}
Also used : XxlJobGroup(com.xxl.job.admin.core.model.XxlJobGroup) SchedulerException(org.quartz.SchedulerException) ReturnT(com.xxl.job.core.biz.model.ReturnT) XxlJobInfo(com.xxl.job.admin.core.model.XxlJobInfo)

Aggregations

XxlJobGroup (com.xxl.job.admin.core.model.XxlJobGroup)7 XxlJobInfo (com.xxl.job.admin.core.model.XxlJobInfo)4 ReturnT (com.xxl.job.core.biz.model.ReturnT)2 ArrayList (java.util.ArrayList)2 ExecutorFailStrategyEnum (com.xxl.job.admin.core.enums.ExecutorFailStrategyEnum)1 XxlJobLog (com.xxl.job.admin.core.model.XxlJobLog)1 XxlJobRegistry (com.xxl.job.admin.core.model.XxlJobRegistry)1 ExecutorRouteStrategyEnum (com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum)1 TriggerParam (com.xxl.job.core.biz.model.TriggerParam)1 ExecutorBlockStrategyEnum (com.xxl.job.core.enums.ExecutorBlockStrategyEnum)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Test (org.junit.Test)1 SchedulerException (org.quartz.SchedulerException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1