com.xxl.job.core.enums.ExecutorBlockStrategyEnum Java Examples

The following examples show how to use com.xxl.job.core.enums.ExecutorBlockStrategyEnum. 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: ExecutorBizTest.java    From xxl-job with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void run(){
    ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken);

    // trigger data
    final TriggerParam triggerParam = new TriggerParam();
    triggerParam.setJobId(1);
    triggerParam.setExecutorHandler("demoJobHandler");
    triggerParam.setExecutorParams(null);
    triggerParam.setExecutorBlockStrategy(ExecutorBlockStrategyEnum.COVER_EARLY.name());
    triggerParam.setGlueType(GlueTypeEnum.BEAN.name());
    triggerParam.setGlueSource(null);
    triggerParam.setGlueUpdatetime(System.currentTimeMillis());
    triggerParam.setLogId(1);
    triggerParam.setLogDateTime(System.currentTimeMillis());

    // Act
    final ReturnT<String> retval = executorBiz.run(triggerParam);

    // Assert result
    Assert.assertNotNull(retval);
}
 
Example #2
Source File: JobInfoController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@RequestMapping
public String index(Model model, @RequestParam(required = false, defaultValue = "-1") int jobGroup) {

	// 枚举-字典
	model.addAttribute("ExecutorRouteStrategyEnum", ExecutorRouteStrategyEnum.values());	// 路由策略-列表
	model.addAttribute("GlueTypeEnum", GlueTypeEnum.values());								// Glue类型-字典
	model.addAttribute("ExecutorBlockStrategyEnum", ExecutorBlockStrategyEnum.values());	// 阻塞处理策略-字典
	model.addAttribute("ExecutorFailStrategyEnum", ExecutorFailStrategyEnum.values());		// 失败处理策略-字典

	// 任务组
	List<XxlJobGroup> jobGroupList =  xxlJobGroupDao.findAll();
	model.addAttribute("JobGroupList", jobGroupList);
	model.addAttribute("jobGroup", jobGroup);

	return "jobinfo/jobinfo.index";
}
 
Example #3
Source File: ManualOperateController.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 测试手动保存任务
 */
@GetMapping("/add")
public String xxlJobAdd() {
    Map<String, Object> jobInfo = Maps.newHashMap();
    jobInfo.put("jobGroup", 2);
    jobInfo.put("jobCron", "0 0/1 * * * ? *");
    jobInfo.put("jobDesc", "手动添加的任务");
    jobInfo.put("author", "admin");
    jobInfo.put("executorRouteStrategy", "ROUND");
    jobInfo.put("executorHandler", "demoTask");
    jobInfo.put("executorParam", "手动添加的任务的参数");
    jobInfo.put("executorBlockStrategy", ExecutorBlockStrategyEnum.SERIAL_EXECUTION);
    jobInfo.put("glueType", GlueTypeEnum.BEAN);

    HttpResponse execute = HttpUtil.createGet(baseUri + JOB_INFO_URI + "/add").form(jobInfo).execute();
    log.info("【execute】= {}", execute);
    return execute.body();
}
 
Example #4
Source File: JobInfoController.java    From xxl-job with GNU General Public License v3.0 6 votes vote down vote up
@RequestMapping
public String index(HttpServletRequest request, Model model, @RequestParam(required = false, defaultValue = "-1") int jobGroup) {

	// 枚举-字典
	model.addAttribute("ExecutorRouteStrategyEnum", ExecutorRouteStrategyEnum.values());	    // 路由策略-列表
	model.addAttribute("GlueTypeEnum", GlueTypeEnum.values());								// Glue类型-字典
	model.addAttribute("ExecutorBlockStrategyEnum", ExecutorBlockStrategyEnum.values());	    // 阻塞处理策略-字典

	// 执行器列表
	List<XxlJobGroup> jobGroupList_all =  xxlJobGroupDao.findAll();

	// filter group
	List<XxlJobGroup> jobGroupList = filterJobGroupByRole(request, jobGroupList_all);
	if (jobGroupList==null || jobGroupList.size()==0) {
		throw new XxlJobException(I18nUtil.getString("jobgroup_empty"));
	}

	model.addAttribute("JobGroupList", jobGroupList);
	model.addAttribute("jobGroup", jobGroup);

	return "jobinfo/jobinfo.index";
}
 
Example #5
Source File: JobInfoController.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping
public String index(Model model, @RequestParam(required = false, defaultValue = "-1") int jobGroup) {

	// 枚举-字典
	model.addAttribute("ExecutorRouteStrategyEnum", ExecutorRouteStrategyEnum.values());	// 路由策略-列表
	model.addAttribute("GlueTypeEnum", GlueTypeEnum.values());								// Glue类型-字典
	model.addAttribute("ExecutorBlockStrategyEnum", ExecutorBlockStrategyEnum.values());	// 阻塞处理策略-字典

	// 任务组
	List<XxlJobGroup> jobGroupList =  xxlJobGroupDao.findAll();
	model.addAttribute("JobGroupList", jobGroupList);
	model.addAttribute("jobGroup", jobGroup);

	return "jobinfo/jobinfo.index";
}
 
Example #6
Source File: ExecutorBizTest.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
/**
 * run jobhandler
 *
 * @param jobHandler
 * @param params
 */
private static void runTest(String jobHandler, String params) throws Exception {
    // trigger data
    TriggerParam triggerParam = new TriggerParam();
    triggerParam.setJobId(1);
    triggerParam.setExecutorHandler(jobHandler);
    triggerParam.setExecutorParams(params);
    triggerParam.setExecutorBlockStrategy(ExecutorBlockStrategyEnum.COVER_EARLY.name());
    triggerParam.setGlueType(GlueTypeEnum.BEAN.name());
    triggerParam.setGlueSource(null);
    triggerParam.setGlueUpdatetime(System.currentTimeMillis());
    triggerParam.setLogId(1);
    triggerParam.setLogDateTim(System.currentTimeMillis());

    // do remote trigger
    String accessToken = null;
    ExecutorBiz executorBiz = (ExecutorBiz) new XxlRpcReferenceBean(
            NetEnum.JETTY,
            Serializer.SerializeEnum.HESSIAN.getSerializer(),
            CallType.SYNC,
            LoadBalance.ROUND,
            ExecutorBiz.class,
            null,
            10000,
            "127.0.0.1:9999",
            null,
            null,
            null).getObject();

    ReturnT<String> runResult = executorBiz.run(triggerParam);

    System.out.println(runResult);
    XxlRpcInvokerFactory.getInstance().stop();
}
 
Example #7
Source File: JobInfoController.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/index1")
public String index1(Model model, @RequestParam(required = false, defaultValue = "-1") Integer jobGroup) {

    // 枚举-字典
    model.addAttribute("ExecutorRouteStrategyEnum", ExecutorRouteStrategyEnum.values());    // 路由策略-列表
    model.addAttribute("GlueTypeEnum", GlueTypeEnum.values());                                // Glue类型-字典
    model.addAttribute("ExecutorBlockStrategyEnum", ExecutorBlockStrategyEnum.values());    // 阻塞处理策略-字典

    // 任务组
    List<XxlJobGroup> jobGroupList = xxlJobGroupDao.findAll();
    model.addAttribute("JobGroupList", jobGroupList);
    model.addAttribute("jobGroup", jobGroup);

    return "jobinfo/jobinfo.index1";
}
 
Example #8
Source File: JobInfoController.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/index2")
public String index2(Model model, @RequestParam(required = false, defaultValue = "-1") Integer jobGroup) {

    // 枚举-字典
    model.addAttribute("ExecutorRouteStrategyEnum", ExecutorRouteStrategyEnum.values());    // 路由策略-列表
    model.addAttribute("GlueTypeEnum", GlueTypeEnum.values());                                // Glue类型-字典
    model.addAttribute("ExecutorBlockStrategyEnum", ExecutorBlockStrategyEnum.values());    // 阻塞处理策略-字典

    // 任务组
    List<XxlJobGroup> jobGroupList = xxlJobGroupDao.findAll();
    model.addAttribute("JobGroupList", jobGroupList);
    model.addAttribute("jobGroup", jobGroup);

    return "jobinfo/jobinfo.index2";
}
 
Example #9
Source File: JobInfoController.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/index1")
public String index1(Model model, @RequestParam(required = false, defaultValue = "-1") Integer jobGroup) {

    // 枚举-字典
    model.addAttribute("ExecutorRouteStrategyEnum", ExecutorRouteStrategyEnum.values());    // 路由策略-列表
    model.addAttribute("GlueTypeEnum", GlueTypeEnum.values());                                // Glue类型-字典
    model.addAttribute("ExecutorBlockStrategyEnum", ExecutorBlockStrategyEnum.values());    // 阻塞处理策略-字典

    // 任务组
    List<XxlJobGroup> jobGroupList = xxlJobGroupDao.findAll();
    model.addAttribute("JobGroupList", jobGroupList);
    model.addAttribute("jobGroup", jobGroup);

    return "jobinfo/jobinfo.index1";
}
 
Example #10
Source File: JobInfoController.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/index2")
public String index2(Model model, @RequestParam(required = false, defaultValue = "-1") Integer jobGroup) {

    // 枚举-字典
    model.addAttribute("ExecutorRouteStrategyEnum", ExecutorRouteStrategyEnum.values());    // 路由策略-列表
    model.addAttribute("GlueTypeEnum", GlueTypeEnum.values());                                // Glue类型-字典
    model.addAttribute("ExecutorBlockStrategyEnum", ExecutorBlockStrategyEnum.values());    // 阻塞处理策略-字典

    // 任务组
    List<XxlJobGroup> jobGroupList = xxlJobGroupDao.findAll();
    model.addAttribute("JobGroupList", jobGroupList);
    model.addAttribute("jobGroup", jobGroup);

    return "jobinfo/jobinfo.index2";
}
 
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> update(XxlJobInfo jobInfo) {

	// valid
	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")) );
	}

	// 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);
	}

	// group valid
	XxlJobGroup jobGroup = xxlJobGroupDao.load(jobInfo.getJobGroup());
	if (jobGroup == null) {
		return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_jobgroup")+I18nUtil.getString("system_unvalid")) );
	}

	// 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")) );
	}

	// next trigger time (5s后生效,避开预读周期)
	long nextTriggerTime = exists_jobInfo.getTriggerNextTime();
	if (exists_jobInfo.getTriggerStatus() == 1 && !jobInfo.getJobCron().equals(exists_jobInfo.getJobCron()) ) {
		try {
			Date nextValidTime = new CronExpression(jobInfo.getJobCron()).getNextValidTimeAfter(new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS));
			if (nextValidTime == null) {
				return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_never_fire"));
			}
			nextTriggerTime = nextValidTime.getTime();
		} catch (ParseException e) {
			logger.error(e.getMessage(), e);
			return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid")+" | "+ e.getMessage());
		}
	}

	exists_jobInfo.setJobGroup(jobInfo.getJobGroup());
	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.setExecutorTimeout(jobInfo.getExecutorTimeout());
	exists_jobInfo.setExecutorFailRetryCount(jobInfo.getExecutorFailRetryCount());
	exists_jobInfo.setChildJobId(jobInfo.getChildJobId());
	exists_jobInfo.setTriggerNextTime(nextTriggerTime);

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


	return ReturnT.SUCCESS;
}
 
Example #12
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 #13
Source File: XxlJobScheduler.java    From xxl-job with GNU General Public License v3.0 4 votes vote down vote up
private void initI18n(){
    for (ExecutorBlockStrategyEnum item:ExecutorBlockStrategyEnum.values()) {
        item.setTitle(I18nUtil.getString("jobconf_block_".concat(item.name())));
    }
}
 
Example #14
Source File: XxlJobTrigger.java    From xxl-job with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param group                     job group, registry list may be empty
 * @param jobInfo
 * @param finalFailRetryCount
 * @param triggerType
 * @param index                     sharding index
 * @param total                     sharding index
 */
private static void processTrigger(XxlJobGroup group, XxlJobInfo jobInfo, int finalFailRetryCount, TriggerTypeEnum triggerType, int index, int total){

    // param
    ExecutorBlockStrategyEnum blockStrategy = ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), ExecutorBlockStrategyEnum.SERIAL_EXECUTION);  // block strategy
    ExecutorRouteStrategyEnum executorRouteStrategyEnum = ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null);    // route strategy
    String shardingParam = (ExecutorRouteStrategyEnum.SHARDING_BROADCAST==executorRouteStrategyEnum)?String.valueOf(index).concat("/").concat(String.valueOf(total)):null;

    // 1、save log-id
    XxlJobLog jobLog = new XxlJobLog();
    jobLog.setJobGroup(jobInfo.getJobGroup());
    jobLog.setJobId(jobInfo.getId());
    jobLog.setTriggerTime(new Date());
    XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().save(jobLog);
    logger.debug(">>>>>>>>>>> xxl-job trigger start, jobId:{}", jobLog.getId());

    // 2、init trigger-param
    TriggerParam triggerParam = new TriggerParam();
    triggerParam.setJobId(jobInfo.getId());
    triggerParam.setExecutorHandler(jobInfo.getExecutorHandler());
    triggerParam.setExecutorParams(jobInfo.getExecutorParam());
    triggerParam.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy());
    triggerParam.setExecutorTimeout(jobInfo.getExecutorTimeout());
    triggerParam.setLogId(jobLog.getId());
    triggerParam.setLogDateTime(jobLog.getTriggerTime().getTime());
    triggerParam.setGlueType(jobInfo.getGlueType());
    triggerParam.setGlueSource(jobInfo.getGlueSource());
    triggerParam.setGlueUpdatetime(jobInfo.getGlueUpdatetime().getTime());
    triggerParam.setBroadcastIndex(index);
    triggerParam.setBroadcastTotal(total);

    // 3、init address
    String address = null;
    ReturnT<String> routeAddressResult = null;
    if (group.getRegistryList()!=null && !group.getRegistryList().isEmpty()) {
        if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST == executorRouteStrategyEnum) {
            if (index < group.getRegistryList().size()) {
                address = group.getRegistryList().get(index);
            } else {
                address = group.getRegistryList().get(0);
            }
        } else {
            routeAddressResult = executorRouteStrategyEnum.getRouter().route(triggerParam, group.getRegistryList());
            if (routeAddressResult.getCode() == ReturnT.SUCCESS_CODE) {
                address = routeAddressResult.getContent();
            }
        }
    } else {
        routeAddressResult = new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobconf_trigger_address_empty"));
    }

    // 4、trigger remote executor
    ReturnT<String> triggerResult = null;
    if (address != null) {
        triggerResult = runExecutor(triggerParam, address);
    } else {
        triggerResult = new ReturnT<String>(ReturnT.FAIL_CODE, null);
    }

    // 5、collection trigger info
    StringBuffer triggerMsgSb = new StringBuffer();
    triggerMsgSb.append(I18nUtil.getString("jobconf_trigger_type")).append(":").append(triggerType.getTitle());
    triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_admin_adress")).append(":").append(IpUtil.getIp());
    triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_exe_regtype")).append(":")
            .append( (group.getAddressType() == 0)?I18nUtil.getString("jobgroup_field_addressType_0"):I18nUtil.getString("jobgroup_field_addressType_1") );
    triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_exe_regaddress")).append(":").append(group.getRegistryList());
    triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorRouteStrategy")).append(":").append(executorRouteStrategyEnum.getTitle());
    if (shardingParam != null) {
        triggerMsgSb.append("("+shardingParam+")");
    }
    triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorBlockStrategy")).append(":").append(blockStrategy.getTitle());
    triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_timeout")).append(":").append(jobInfo.getExecutorTimeout());
    triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorFailRetryCount")).append(":").append(finalFailRetryCount);

    triggerMsgSb.append("<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_run") +"<<<<<<<<<<< </span><br>")
            .append((routeAddressResult!=null&&routeAddressResult.getMsg()!=null)?routeAddressResult.getMsg()+"<br><br>":"").append(triggerResult.getMsg()!=null?triggerResult.getMsg():"");

    // 6、save log trigger-info
    jobLog.setExecutorAddress(address);
    jobLog.setExecutorHandler(jobInfo.getExecutorHandler());
    jobLog.setExecutorParam(jobInfo.getExecutorParam());
    jobLog.setExecutorShardingParam(shardingParam);
    jobLog.setExecutorFailRetryCount(finalFailRetryCount);
    //jobLog.setTriggerTime();
    jobLog.setTriggerCode(triggerResult.getCode());
    jobLog.setTriggerMsg(triggerMsgSb.toString());
    XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateTriggerInfo(jobLog);

    logger.debug(">>>>>>>>>>> xxl-job trigger end, jobId:{}", jobLog.getId());
}
 
Example #15
Source File: XxlJobDynamicScheduler.java    From zuihou-admin-cloud with Apache License 2.0 4 votes vote down vote up
private void initI18n() {
    for (ExecutorBlockStrategyEnum item : ExecutorBlockStrategyEnum.values()) {
        item.setTitle(I18nUtil.getString("jobconf_block_".concat(item.name())));
    }
}
 
Example #16
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 #17
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;
}
 
Example #18
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 #19
Source File: XxlJobDynamicScheduler.java    From zuihou-admin-boot with Apache License 2.0 4 votes vote down vote up
private void initI18n() {
    for (ExecutorBlockStrategyEnum item : ExecutorBlockStrategyEnum.values()) {
        item.setTitle(I18nUtil.getString("jobconf_block_".concat(item.name())));
    }
}
 
Example #20
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 #21
Source File: XxlJobTrigger.java    From microservices-platform with Apache License 2.0 4 votes vote down vote up
/**
 * @param group                     job group, registry list may be empty
 * @param jobInfo
 * @param finalFailRetryCount
 * @param triggerType
 * @param index                     sharding index
 * @param total                     sharding index
 */
private static void processTrigger(XxlJobGroup group, XxlJobInfo jobInfo, int finalFailRetryCount, TriggerTypeEnum triggerType, int index, int total){

    // param
    ExecutorBlockStrategyEnum blockStrategy = ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), ExecutorBlockStrategyEnum.SERIAL_EXECUTION);  // block strategy
    ExecutorRouteStrategyEnum executorRouteStrategyEnum = ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null);    // route strategy
    String shardingParam = (ExecutorRouteStrategyEnum.SHARDING_BROADCAST==executorRouteStrategyEnum)?String.valueOf(index).concat("/").concat(String.valueOf(total)):null;

    // 1、save log-id
    XxlJobLog jobLog = new XxlJobLog();
    jobLog.setJobGroup(jobInfo.getJobGroup());
    jobLog.setJobId(jobInfo.getId());
    jobLog.setTriggerTime(new Date());
    XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().save(jobLog);
    logger.debug(">>>>>>>>>>> xxl-job trigger start, jobId:{}", jobLog.getId());

    // 2、init trigger-param
    TriggerParam triggerParam = new TriggerParam();
    triggerParam.setJobId(jobInfo.getId());
    triggerParam.setExecutorHandler(jobInfo.getExecutorHandler());
    triggerParam.setExecutorParams(jobInfo.getExecutorParam());
    triggerParam.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy());
    triggerParam.setExecutorTimeout(jobInfo.getExecutorTimeout());
    triggerParam.setLogId(jobLog.getId());
    triggerParam.setLogDateTim(jobLog.getTriggerTime().getTime());
    triggerParam.setGlueType(jobInfo.getGlueType());
    triggerParam.setGlueSource(jobInfo.getGlueSource());
    triggerParam.setGlueUpdatetime(jobInfo.getGlueUpdatetime().getTime());
    triggerParam.setBroadcastIndex(index);
    triggerParam.setBroadcastTotal(total);

    // 3、init address
    String address = null;
    ReturnT<String> routeAddressResult = null;
    if (group.getRegistryList()!=null && !group.getRegistryList().isEmpty()) {
        if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST == executorRouteStrategyEnum) {
            if (index < group.getRegistryList().size()) {
                address = group.getRegistryList().get(index);
            } else {
                address = group.getRegistryList().get(0);
            }
        } else {
            routeAddressResult = executorRouteStrategyEnum.getRouter().route(triggerParam, group.getRegistryList());
            if (routeAddressResult.getCode() == ReturnT.SUCCESS_CODE) {
                address = routeAddressResult.getContent();
            }
        }
    } else {
        routeAddressResult = new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobconf_trigger_address_empty"));
    }

    // 4、trigger remote executor
    ReturnT<String> triggerResult = null;
    if (address != null) {
        triggerResult = runExecutor(triggerParam, address);
    } else {
        triggerResult = new ReturnT<String>(ReturnT.FAIL_CODE, null);
    }

    // 5、collection trigger info
    StringBuffer triggerMsgSb = new StringBuffer();
    triggerMsgSb.append(I18nUtil.getString("jobconf_trigger_type")).append(":").append(triggerType.getTitle());
    triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_admin_adress")).append(":").append(IpUtil.getIp());
    triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_exe_regtype")).append(":")
            .append( (group.getAddressType() == 0)?I18nUtil.getString("jobgroup_field_addressType_0"):I18nUtil.getString("jobgroup_field_addressType_1") );
    triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_exe_regaddress")).append(":").append(group.getRegistryList());
    triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorRouteStrategy")).append(":").append(executorRouteStrategyEnum.getTitle());
    if (shardingParam != null) {
        triggerMsgSb.append("("+shardingParam+")");
    }
    triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorBlockStrategy")).append(":").append(blockStrategy.getTitle());
    triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_timeout")).append(":").append(jobInfo.getExecutorTimeout());
    triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorFailRetryCount")).append(":").append(finalFailRetryCount);

    triggerMsgSb.append("<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_run") +"<<<<<<<<<<< </span><br>")
            .append((routeAddressResult!=null&&routeAddressResult.getMsg()!=null)?routeAddressResult.getMsg()+"<br><br>":"").append(triggerResult.getMsg()!=null?triggerResult.getMsg():"");

    // 6、save log trigger-info
    jobLog.setExecutorAddress(address);
    jobLog.setExecutorHandler(jobInfo.getExecutorHandler());
    jobLog.setExecutorParam(jobInfo.getExecutorParam());
    jobLog.setExecutorShardingParam(shardingParam);
    jobLog.setExecutorFailRetryCount(finalFailRetryCount);
    //jobLog.setTriggerTime();
    jobLog.setTriggerCode(triggerResult.getCode());
    jobLog.setTriggerMsg(triggerMsgSb.toString());
    XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateTriggerInfo(jobLog);

    logger.debug(">>>>>>>>>>> xxl-job trigger end, jobId:{}", jobLog.getId());
}
 
Example #22
Source File: XxlJobDynamicScheduler.java    From microservices-platform with Apache License 2.0 4 votes vote down vote up
private void initI18n(){
    for (ExecutorBlockStrategyEnum item:ExecutorBlockStrategyEnum.values()) {
        item.setTitle(I18nUtil.getString("jobconf_block_".concat(item.name())));
    }
}
 
Example #23
Source File: XxlJobServiceImpl.java    From microservices-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")) );
	}

	// 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 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.setExecutorTimeout(jobInfo.getExecutorTimeout());
	exists_jobInfo.setExecutorFailRetryCount(jobInfo.getExecutorFailRetryCount());
	exists_jobInfo.setChildJobId(jobInfo.getChildJobId());
       xxlJobInfoDao.update(exists_jobInfo);


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

	return ReturnT.SUCCESS;
}
 
Example #24
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 #25
Source File: XxlJobDynamicScheduler.java    From open-capacity-platform with Apache License 2.0 4 votes vote down vote up
private void initI18n(){
    for (ExecutorBlockStrategyEnum item:ExecutorBlockStrategyEnum.values()) {
        item.setTitle(I18nUtil.getString("jobconf_block_".concat(item.name())));
    }
}
 
Example #26
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 #27
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());
       }
}