Java Code Examples for com.xxl.job.admin.core.model.XxlJobInfo#setGlueSource()

The following examples show how to use com.xxl.job.admin.core.model.XxlJobInfo#setGlueSource() . 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: JobCodeController.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/save")
@ResponseBody
public ReturnT<String> save(Model model, int id, String glueSource, String glueRemark) {
	// valid
	if (glueRemark==null) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_glue_remark")) );
	}
	if (glueRemark.length()<4 || glueRemark.length()>100) {
		return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_remark_limit"));
	}
	XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(id);
	if (exists_jobInfo == null) {
		return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
	}
	
	// update new code
	exists_jobInfo.setGlueSource(glueSource);
	exists_jobInfo.setGlueRemark(glueRemark);
	exists_jobInfo.setGlueUpdatetime(new Date());
	xxlJobInfoDao.update(exists_jobInfo);

	// log old code
	XxlJobLogGlue xxlJobLogGlue = new XxlJobLogGlue();
	xxlJobLogGlue.setJobId(exists_jobInfo.getId());
	xxlJobLogGlue.setGlueType(exists_jobInfo.getGlueType());
	xxlJobLogGlue.setGlueSource(glueSource);
	xxlJobLogGlue.setGlueRemark(glueRemark);
	xxlJobLogGlueDao.save(xxlJobLogGlue);

	// remove code backup more than 30
	xxlJobLogGlueDao.removeOld(exists_jobInfo.getId(), 30);

	return ReturnT.SUCCESS;
}
 
Example 2
Source File: JobCodeController.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/save")
@ResponseBody
public ReturnT<String> save(Model model, int id, String glueSource, String glueRemark) {
	// valid
	if (glueRemark==null) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_glue_remark")) );
	}
	if (glueRemark.length()<4 || glueRemark.length()>100) {
		return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_remark_limit"));
	}
	XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(id);
	if (exists_jobInfo == null) {
		return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
	}
	
	// update new code
	exists_jobInfo.setGlueSource(glueSource);
	exists_jobInfo.setGlueRemark(glueRemark);
	exists_jobInfo.setGlueUpdatetime(new Date());
	xxlJobInfoDao.update(exists_jobInfo);

	// log old code
	XxlJobLogGlue xxlJobLogGlue = new XxlJobLogGlue();
	xxlJobLogGlue.setJobId(exists_jobInfo.getId());
	xxlJobLogGlue.setGlueType(exists_jobInfo.getGlueType());
	xxlJobLogGlue.setGlueSource(glueSource);
	xxlJobLogGlue.setGlueRemark(glueRemark);
	xxlJobLogGlueDao.save(xxlJobLogGlue);

	// remove code backup more than 30
	xxlJobLogGlueDao.removeOld(exists_jobInfo.getId(), 30);

	return ReturnT.SUCCESS;
}
 
Example 3
Source File: JobCodeController.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/save")
@ResponseBody
public ReturnT<String> save(Model model, Integer id, String glueSource, String glueRemark) {
    // valid
    if (glueRemark == null) {
        return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_glue_remark")));
    }
    if (glueRemark.length() < 4 || glueRemark.length() > 100) {
        return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_remark_limit"));
    }
    XxlJobInfo existsJobinfo = xxlJobInfoDao.loadById(id);
    if (existsJobinfo == null) {
        return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
    }

    // update new code
    existsJobinfo.setGlueSource(glueSource);
    existsJobinfo.setGlueRemark(glueRemark);
    existsJobinfo.setGlueUpdatetime(new Date());
    xxlJobInfoDao.update(existsJobinfo);

    // log old code
    XxlJobLogGlue xxlJobLogGlue = new XxlJobLogGlue();
    xxlJobLogGlue.setJobId(existsJobinfo.getId());
    xxlJobLogGlue.setGlueType(existsJobinfo.getGlueType());
    xxlJobLogGlue.setGlueSource(glueSource);
    xxlJobLogGlue.setGlueRemark(glueRemark);
    xxlJobLogGlueDao.save(xxlJobLogGlue);

    // remove code backup more than 30
    xxlJobLogGlueDao.removeOld(existsJobinfo.getId(), 30);

    return ReturnT.SUCCESS;
}
 
Example 4
Source File: JobCodeController.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/save")
@ResponseBody
public ReturnT<String> save(Model model, Integer id, String glueSource, String glueRemark) {
    // valid
    if (glueRemark == null) {
        return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_glue_remark")));
    }
    if (glueRemark.length() < 4 || glueRemark.length() > 100) {
        return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_remark_limit"));
    }
    XxlJobInfo existsJobinfo = xxlJobInfoDao.loadById(id);
    if (existsJobinfo == null) {
        return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
    }

    // update new code
    existsJobinfo.setGlueSource(glueSource);
    existsJobinfo.setGlueRemark(glueRemark);
    existsJobinfo.setGlueUpdatetime(new Date());
    xxlJobInfoDao.update(existsJobinfo);

    // log old code
    XxlJobLogGlue xxlJobLogGlue = new XxlJobLogGlue();
    xxlJobLogGlue.setJobId(existsJobinfo.getId());
    xxlJobLogGlue.setGlueType(existsJobinfo.getGlueType());
    xxlJobLogGlue.setGlueSource(glueSource);
    xxlJobLogGlue.setGlueRemark(glueRemark);
    xxlJobLogGlueDao.save(xxlJobLogGlue);

    // remove code backup more than 30
    xxlJobLogGlueDao.removeOld(existsJobinfo.getId(), 30);

    return ReturnT.SUCCESS;
}
 
Example 5
Source File: JobCodeController.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping("/save")
@ResponseBody
public ReturnT<String> save(Model model, int id, String glueSource, String glueRemark) {
	// valid
	if (glueRemark==null) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_glue_remark")) );
	}
	if (glueRemark.length()<4 || glueRemark.length()>100) {
		return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_remark_limit"));
	}
	XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(id);
	if (exists_jobInfo == null) {
		return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
	}
	
	// update new code
	exists_jobInfo.setGlueSource(glueSource);
	exists_jobInfo.setGlueRemark(glueRemark);
	exists_jobInfo.setGlueUpdatetime(new Date());

	exists_jobInfo.setUpdateTime(new Date());
	xxlJobInfoDao.update(exists_jobInfo);

	// log old code
	XxlJobLogGlue xxlJobLogGlue = new XxlJobLogGlue();
	xxlJobLogGlue.setJobId(exists_jobInfo.getId());
	xxlJobLogGlue.setGlueType(exists_jobInfo.getGlueType());
	xxlJobLogGlue.setGlueSource(glueSource);
	xxlJobLogGlue.setGlueRemark(glueRemark);

	xxlJobLogGlue.setAddTime(new Date());
	xxlJobLogGlue.setUpdateTime(new Date());
	xxlJobLogGlueDao.save(xxlJobLogGlue);

	// remove code backup more than 30
	xxlJobLogGlueDao.removeOld(exists_jobInfo.getId(), 30);

	return ReturnT.SUCCESS;
}
 
Example 6
Source File: XxlJobServiceImpl.java    From open-capacity-platform with Apache License 2.0 4 votes vote down vote up
@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());
       }
}
 
Example 7
Source File: XxlJobServiceImpl.java    From microservices-platform with Apache License 2.0 4 votes vote down vote up
@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 (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")) );
	}

	return new ReturnT<String>(String.valueOf(jobInfo.getId()));
}
 
Example 8
Source File: XxlJobInfoDaoTest.java    From microservices-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void save_load(){
	XxlJobInfo info = new XxlJobInfo();
	info.setJobGroup(1);
	info.setJobCron("jobCron");
	info.setJobDesc("desc");
	info.setAuthor("setAuthor");
	info.setAlarmEmail("setAlarmEmail");
	info.setExecutorRouteStrategy("setExecutorRouteStrategy");
	info.setExecutorHandler("setExecutorHandler");
	info.setExecutorParam("setExecutorParam");
	info.setExecutorBlockStrategy("setExecutorBlockStrategy");
	info.setGlueType("setGlueType");
	info.setGlueSource("setGlueSource");
	info.setGlueRemark("setGlueRemark");
	info.setChildJobId("1");

	int count = xxlJobInfoDao.save(info);

	XxlJobInfo info2 = xxlJobInfoDao.loadById(info.getId());
	info2.setJobCron("jobCron2");
	info2.setJobDesc("desc2");
	info2.setAuthor("setAuthor2");
	info2.setAlarmEmail("setAlarmEmail2");
	info2.setExecutorRouteStrategy("setExecutorRouteStrategy2");
	info2.setExecutorHandler("setExecutorHandler2");
	info2.setExecutorParam("setExecutorParam2");
	info2.setExecutorBlockStrategy("setExecutorBlockStrategy2");
	info2.setGlueType("setGlueType2");
	info2.setGlueSource("setGlueSource2");
	info2.setGlueRemark("setGlueRemark2");
	info2.setGlueUpdatetime(new Date());
	info2.setChildJobId("1");

	int item2 = xxlJobInfoDao.update(info2);

	xxlJobInfoDao.delete(info2.getId());

	List<XxlJobInfo> list2 = xxlJobInfoDao.getJobsByGroup(1);

	int ret3 = xxlJobInfoDao.findAllCount();

}
 
Example 9
Source File: XxlJobServiceImpl.java    From zuihou-admin-boot with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnT<String> add(XxlJobInfo jobInfo) {
    // valid 执行器是否存在
    XxlJobGroup group = xxlJobGroupDao.load(jobInfo.getJobGroup());
    if (group == null) {
        group = xxlJobGroupDao.getByName(jobInfo.getJobGroupName());
        if (group == null) {
            return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_choose") + I18nUtil.getString("jobinfo_field_jobgroup")));
        }
        jobInfo.setJobGroup(group.getId());
    }


    if (JobTypeEnum.CRON.eq(jobInfo.getType())) {
        if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
            return new ReturnT<>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid"));
        }
    } else {
        jobInfo.setType(JobTypeEnum.TIMES.getCode());
        //表单校验
        String msg = validate(jobInfo.getIntervalSeconds(), jobInfo.getRepeatCount(),
                jobInfo.getStartExecuteTime(), jobInfo.getEndExecuteTime());
        if (!StringUtils.isEmpty(msg)) {
            return new ReturnT<>(ReturnT.FAIL_CODE, msg);
        }
    }
    if (GlueTypeEnum.BEAN == GlueTypeEnum.match(jobInfo.getGlueType()) && StringUtils.isBlank(jobInfo.getExecutorHandler())) {
        return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input") + "JobHandler"));
    }

    if (StringUtils.isBlank(jobInfo.getJobDesc())) {
        jobInfo.setJobDesc("任务描述");
    }
    if (StringUtils.isBlank(jobInfo.getAuthor())) {
        jobInfo.setAuthor("admin");
    }
    if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
        jobInfo.setExecutorRouteStrategy(ExecutorRouteStrategyEnum.FIRST.name());
    }
    if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
        jobInfo.setExecutorBlockStrategy(ExecutorBlockStrategyEnum.SERIAL_EXECUTION.name());
    }
    if (GlueTypeEnum.match(jobInfo.getGlueType()) == null) {
        jobInfo.setGlueType(GlueTypeEnum.BEAN.name());
    }
    // 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")));
    }

    return new ReturnT<String>(String.valueOf(jobInfo.getId()));
}
 
Example 10
Source File: XxlJobServiceImpl.java    From zuihou-admin-cloud with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnT<String> add(XxlJobInfo jobInfo) {
    // valid 执行器是否存在
    XxlJobGroup group = xxlJobGroupDao.load(jobInfo.getJobGroup());
    if (group == null) {
        group = xxlJobGroupDao.getByName(jobInfo.getJobGroupName());
        if (group == null) {
            return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_choose") + I18nUtil.getString("jobinfo_field_jobgroup")));
        }
        jobInfo.setJobGroup(group.getId());
    }


    if (JobTypeEnum.CRON.eq(jobInfo.getType())) {
        if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
            return new ReturnT<>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid"));
        }
    } else {
        jobInfo.setType(JobTypeEnum.TIMES.getCode());
        //表单校验
        String msg = validate(jobInfo.getIntervalSeconds(), jobInfo.getRepeatCount(),
                jobInfo.getStartExecuteTime(), jobInfo.getEndExecuteTime());
        if (!StringUtils.isEmpty(msg)) {
            return new ReturnT<>(ReturnT.FAIL_CODE, msg);
        }
    }
    if (GlueTypeEnum.BEAN == GlueTypeEnum.match(jobInfo.getGlueType()) && StringUtils.isBlank(jobInfo.getExecutorHandler())) {
        return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input") + "JobHandler"));
    }

    if (StringUtils.isBlank(jobInfo.getJobDesc())) {
        jobInfo.setJobDesc("任务描述");
    }
    if (StringUtils.isBlank(jobInfo.getAuthor())) {
        jobInfo.setAuthor("admin");
    }
    if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
        jobInfo.setExecutorRouteStrategy(ExecutorRouteStrategyEnum.FIRST.name());
    }
    if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
        jobInfo.setExecutorBlockStrategy(ExecutorBlockStrategyEnum.SERIAL_EXECUTION.name());
    }
    if (GlueTypeEnum.match(jobInfo.getGlueType()) == null) {
        jobInfo.setGlueType(GlueTypeEnum.BEAN.name());
    }
    // 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")));
    }

    return new ReturnT<String>(String.valueOf(jobInfo.getId()));
}
 
Example 11
Source File: XxlJobServiceImpl.java    From xxl-job with GNU General Public License v3.0 4 votes vote down vote up
@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 (jobInfo.getJobDesc()==null || jobInfo.getJobDesc().trim().length()==0) {
		return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) );
	}
	if (jobInfo.getAuthor()==null || jobInfo.getAuthor().trim().length()==0) {
		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 (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()) && (jobInfo.getExecutorHandler()==null || jobInfo.getExecutorHandler().trim().length()==0) ) {
		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 (jobInfo.getChildJobId()!=null && jobInfo.getChildJobId().trim().length()>0) {
		String[] childJobIds = jobInfo.getChildJobId().split(",");
		for (String childJobIdItem: childJobIds) {
			if (childJobIdItem!=null && childJobIdItem.trim().length()>0 && isNumeric(childJobIdItem)) {
				XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.parseInt(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));
			}
		}

		// join , avoid "xxx,,"
		String temp = "";
		for (String item:childJobIds) {
			temp += item + ",";
		}
		temp = temp.substring(0, temp.length()-1);

		jobInfo.setChildJobId(temp);
	}

	// add in db
	jobInfo.setAddTime(new Date());
	jobInfo.setUpdateTime(new Date());
	jobInfo.setGlueUpdatetime(new Date());
	xxlJobInfoDao.save(jobInfo);
	if (jobInfo.getId() < 1) {
		return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_add")+I18nUtil.getString("system_fail")) );
	}

	return new ReturnT<String>(String.valueOf(jobInfo.getId()));
}
 
Example 12
Source File: XxlJobInfoDaoTest.java    From xxl-job with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void save_load(){
	XxlJobInfo info = new XxlJobInfo();
	info.setJobGroup(1);
	info.setJobCron("jobCron");
	info.setJobDesc("desc");
	info.setAuthor("setAuthor");
	info.setAlarmEmail("setAlarmEmail");
	info.setExecutorRouteStrategy("setExecutorRouteStrategy");
	info.setExecutorHandler("setExecutorHandler");
	info.setExecutorParam("setExecutorParam");
	info.setExecutorBlockStrategy("setExecutorBlockStrategy");
	info.setGlueType("setGlueType");
	info.setGlueSource("setGlueSource");
	info.setGlueRemark("setGlueRemark");
	info.setChildJobId("1");

	info.setAddTime(new Date());
	info.setUpdateTime(new Date());
	info.setGlueUpdatetime(new Date());

	int count = xxlJobInfoDao.save(info);

	XxlJobInfo info2 = xxlJobInfoDao.loadById(info.getId());
	info2.setJobCron("jobCron2");
	info2.setJobDesc("desc2");
	info2.setAuthor("setAuthor2");
	info2.setAlarmEmail("setAlarmEmail2");
	info2.setExecutorRouteStrategy("setExecutorRouteStrategy2");
	info2.setExecutorHandler("setExecutorHandler2");
	info2.setExecutorParam("setExecutorParam2");
	info2.setExecutorBlockStrategy("setExecutorBlockStrategy2");
	info2.setGlueType("setGlueType2");
	info2.setGlueSource("setGlueSource2");
	info2.setGlueRemark("setGlueRemark2");
	info2.setGlueUpdatetime(new Date());
	info2.setChildJobId("1");

	info2.setUpdateTime(new Date());
	int item2 = xxlJobInfoDao.update(info2);

	xxlJobInfoDao.delete(info2.getId());

	List<XxlJobInfo> list2 = xxlJobInfoDao.getJobsByGroup(1);

	int ret3 = xxlJobInfoDao.findAllCount();

}