| | |
| | | * |
| | | * @param jobId |
| | | * @param triggerType |
| | | * @param failRetryCount |
| | | * >=0: use this param |
| | | * <0: use param from job info config |
| | | * @param failRetryCount >=0: use this param |
| | | * <0: use param from job info config |
| | | * @param executorShardingParam |
| | | * @param executorParam |
| | | * null: use job param |
| | | * not null: cover job param |
| | | * @param addressList |
| | | * null: use executor addressList |
| | | * not null: cover |
| | | * @param executorParam null: use job param |
| | | * not null: cover job param |
| | | * @param addressList null: use executor addressList |
| | | * not null: cover |
| | | */ |
| | | public static void trigger(int jobId, |
| | | TriggerTypeEnum triggerType, |
| | |
| | | if (executorParam != null) { |
| | | jobInfo.setExecutorParam(executorParam); |
| | | } |
| | | int finalFailRetryCount = failRetryCount>=0?failRetryCount:jobInfo.getExecutorFailRetryCount(); |
| | | int finalFailRetryCount = failRetryCount >= 0 ? failRetryCount : jobInfo.getExecutorFailRetryCount(); |
| | | XxlJobGroup group = XxlJobAdminConfig.getAdminConfig().getXxlJobGroupDao().load(jobInfo.getJobGroup()); |
| | | |
| | | // cover addressList |
| | | if (addressList!=null && addressList.trim().length()>0) { |
| | | if (addressList != null && addressList.trim().length() > 0) { |
| | | group.setAddressType(1); |
| | | group.setAddressList(addressList.trim()); |
| | | } |
| | | |
| | | // sharding param |
| | | int[] shardingParam = null; |
| | | if (executorShardingParam!=null){ |
| | | if (executorShardingParam != null) { |
| | | String[] shardingArr = executorShardingParam.split("/"); |
| | | if (shardingArr.length==2 && isNumeric(shardingArr[0]) && isNumeric(shardingArr[1])) { |
| | | if (shardingArr.length == 2 && isNumeric(shardingArr[0]) && isNumeric(shardingArr[1])) { |
| | | shardingParam = new int[2]; |
| | | shardingParam[0] = Integer.valueOf(shardingArr[0]); |
| | | shardingParam[1] = Integer.valueOf(shardingArr[1]); |
| | | } |
| | | } |
| | | if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST==ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) |
| | | && group.getRegistryList()!=null && !group.getRegistryList().isEmpty() |
| | | && shardingParam==null) { |
| | | if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST == ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) |
| | | && group.getRegistryList() != null && !group.getRegistryList().isEmpty() |
| | | && shardingParam == null) { |
| | | for (int i = 0; i < group.getRegistryList().size(); i++) { |
| | | processTrigger(group, jobInfo, finalFailRetryCount, triggerType, i, group.getRegistryList().size()); |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | private static boolean isNumeric(String str){ |
| | | private static boolean isNumeric(String str) { |
| | | try { |
| | | int result = Integer.valueOf(str); |
| | | return true; |
| | |
| | | } |
| | | |
| | | /** |
| | | * @param group job group, registry list may be empty |
| | | * @param group job group, registry list may be empty |
| | | * @param jobInfo |
| | | * @param finalFailRetryCount |
| | | * @param triggerType |
| | | * @param index sharding index |
| | | * @param total sharding index |
| | | * @param index sharding index |
| | | * @param total sharding index |
| | | */ |
| | | private static void processTrigger(XxlJobGroup group, XxlJobInfo jobInfo, int finalFailRetryCount, TriggerTypeEnum triggerType, int index, int total){ |
| | | 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; |
| | | String shardingParam = (ExecutorRouteStrategyEnum.SHARDING_BROADCAST == executorRouteStrategyEnum) ? String.valueOf(index).concat("/").concat(String.valueOf(total)) : null; |
| | | |
| | | // 1、save log-id |
| | | XxlJobLog jobLog = new XxlJobLog(); |
| | |
| | | // 3、init address |
| | | String address = null; |
| | | ReturnT<String> routeAddressResult = null; |
| | | if (group.getRegistryList()!=null && !group.getRegistryList().isEmpty()) { |
| | | if (group.getRegistryList() != null && !group.getRegistryList().isEmpty()) { |
| | | if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST == executorRouteStrategyEnum) { |
| | | if (index < group.getRegistryList().size()) { |
| | | address = group.getRegistryList().get(index); |
| | |
| | | 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") ); |
| | | .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("(" + 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():""); |
| | | 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); |
| | |
| | | |
| | | /** |
| | | * run executor |
| | | * |
| | | * @param triggerParam |
| | | * @param address |
| | | * @return |
| | | */ |
| | | public static ReturnT<String> runExecutor(TriggerParam triggerParam, String address){ |
| | | public static ReturnT<String> runExecutor(TriggerParam triggerParam, String address) { |
| | | ReturnT<String> runResult = null; |
| | | try { |
| | | ExecutorBiz executorBiz = XxlJobScheduler.getExecutorBiz(address); |