Java Code Examples for com.xxl.job.admin.core.util.I18nUtil#getString()

The following examples show how to use com.xxl.job.admin.core.util.I18nUtil#getString() . 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: JobLogController.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/logDetailPage")
public String logDetailPage(Integer id, Model model) {

    // base check
    ReturnT<String> logStatue = ReturnT.SUCCESS;
    XxlJobLog jobLog = xxlJobLogDao.load(id);
    if (jobLog == null) {
        throw new RuntimeException(I18nUtil.getString("joblog_logid_unvalid"));
    }

    model.addAttribute("triggerCode", jobLog.getTriggerCode());
    model.addAttribute("handleCode", jobLog.getHandleCode());
    model.addAttribute("executorAddress", jobLog.getExecutorAddress());
    model.addAttribute("triggerTime", jobLog.getTriggerTime().getTime());
    model.addAttribute("logId", jobLog.getId());
    return "joblog/joblog.detail";
}
 
Example 2
Source File: JobGroupController.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/remove")
@ResponseBody
public ReturnT<String> remove(Integer id, Integer type) {

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

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

    int ret = xxlJobGroupDao.remove(id);
    return (ret > 0) ? ReturnT.SUCCESS : ReturnT.FAIL;
}
 
Example 3
Source File: XxlJobTrigger.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * run executor
 *
 * @param triggerParam
 * @param address
 * @return
 */
public static ReturnT<String> runExecutor(TriggerParam triggerParam, String address) {
    ReturnT<String> runResult = null;
    try {
        ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(address);
        runResult = executorBiz.run(triggerParam);
    } catch (Exception e) {
        logger.error(">>>>>>>>>>> xxl-job trigger error, please check if the executor[{}] is running.", address, e);
        runResult = new ReturnT<String>(ReturnT.FAIL_CODE, ThrowableUtil.toString(e));
    }

    StringBuffer runResultSB = new StringBuffer(I18nUtil.getString("jobconf_trigger_run") + ":");
    runResultSB.append("<br>address:").append(address);
    runResultSB.append("<br>code:").append(runResult.getCode());
    runResultSB.append("<br>msg:").append(runResult.getMsg());

    runResult.setMsg(runResultSB.toString());
    return runResult;
}
 
Example 4
Source File: XxlJobTrigger.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
/**
 * run executor
 *
 * @param triggerParam
 * @param address
 * @return
 */
public static ReturnT<String> runExecutor(TriggerParam triggerParam, String address) {
    ReturnT<String> runResult = null;
    try {
        ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(address);
        runResult = executorBiz.run(triggerParam);
    } catch (Exception e) {
        logger.error(">>>>>>>>>>> xxl-job trigger error, please check if the executor[{}] is running.", address, e);
        runResult = new ReturnT<String>(ReturnT.FAIL_CODE, ThrowableUtil.toString(e));
    }

    StringBuffer runResultSB = new StringBuffer(I18nUtil.getString("jobconf_trigger_run") + ":");
    runResultSB.append("<br>address:").append(address);
    runResultSB.append("<br>code:").append(runResult.getCode());
    runResultSB.append("<br>msg:").append(runResult.getMsg());

    runResult.setMsg(runResultSB.toString());
    return runResult;
}
 
Example 5
Source File: IndexController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value="login", method=RequestMethod.POST)
@ResponseBody
@PermessionLimit(limit=false)
public ReturnT<String> loginDo(HttpServletRequest request, HttpServletResponse response, String userName, String password, String ifRemember){
	// valid
	if (PermissionInterceptor.ifLogin(request)) {
		return ReturnT.SUCCESS;
	}

	// param
	if (StringUtils.isBlank(userName) || StringUtils.isBlank(password)){
		return new ReturnT<String>(500, I18nUtil.getString("login_param_empty"));
	}
	boolean ifRem = (StringUtils.isNotBlank(ifRemember) && "on".equals(ifRemember))?true:false;

	// do login
	boolean loginRet = PermissionInterceptor.login(response, userName, password, ifRem);
	if (!loginRet) {
		return new ReturnT<String>(500, I18nUtil.getString("login_param_unvalid"));
	}
	return ReturnT.SUCCESS;
}
 
Example 6
Source File: XxlJobTrigger.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
/**
 * run executor
 * @param triggerParam
 * @param address
 * @return
 */
public static ReturnT<String> runExecutor(TriggerParam triggerParam, String address){
    ReturnT<String> runResult = null;
    try {
        ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(address);
        runResult = executorBiz.run(triggerParam);
    } catch (Exception e) {
        logger.error(">>>>>>>>>>> xxl-job trigger error, please check if the executor[{}] is running.", address, e);
        runResult = new ReturnT<String>(ReturnT.FAIL_CODE, ThrowableUtil.toString(e));
    }

    StringBuffer runResultSB = new StringBuffer(I18nUtil.getString("jobconf_trigger_run") + ":");
    runResultSB.append("<br>address:").append(address);
    runResultSB.append("<br>code:").append(runResult.getCode());
    runResultSB.append("<br>msg:").append(runResult.getMsg());

    runResult.setMsg(runResultSB.toString());
    return runResult;
}
 
Example 7
Source File: XxlJobServiceImpl.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> start(Integer id) {
    XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
    if (JobTypeEnum.CRON.eq(xxlJobInfo.getType())) {
        if (!CronExpression.isValidExpression(xxlJobInfo.getJobCron())) {
            return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid"));
        }
    } else {
        //表单校验
        String msg = validate(xxlJobInfo.getIntervalSeconds(), xxlJobInfo.getRepeatCount(),
                xxlJobInfo.getStartExecuteTime(), xxlJobInfo.getEndExecuteTime());
        if (!StringUtils.isEmpty(msg)) {
            return new ReturnT<String>(ReturnT.FAIL_CODE, msg);
        }
    }
    String group = String.valueOf(xxlJobInfo.getJobGroup());
    String name = String.valueOf(xxlJobInfo.getId());
    String cronExpression = xxlJobInfo.getJobCron();
    boolean ret = false;
    try {
        //判断定时类型
        if (JobTypeEnum.CRON.eq(xxlJobInfo.getType())) {
            ret = XxlJobDynamicScheduler.addJob(name, group, cronExpression);
        } else {
            /*if (!DateUtil.isMatch(xxlJobInfo.get())) {
                return new ReturnT<>(ReturnT.START_JOB_FAI, "触发时间不能小于当前时间.");
            }*/
            ret = XxlJobDynamicScheduler.addJob(name, group, xxlJobInfo.getStartExecuteTime(), xxlJobInfo.getEndExecuteTime(), xxlJobInfo.getIntervalSeconds(), xxlJobInfo.getRepeatCount());
        }
        return ret ? ReturnT.SUCCESS : ReturnT.FAIL;
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        return ReturnT.FAIL;
    }
}
 
Example 8
Source File: JobFailMonitorHelper.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
/**
 * fail alarm
 *
 * @param jobLog
 */
private void failAlarm(XxlJobInfo info, XxlJobLog jobLog) {

    // send monitor email
    if (info != null && info.getAlarmEmail() != null && info.getAlarmEmail().trim().length() > 0) {

        String alarmContent = "Alarm Job LogId=" + jobLog.getId();
        if (jobLog.getTriggerCode() != ReturnT.SUCCESS_CODE) {
            alarmContent += "<br>TriggerMsg=" + jobLog.getTriggerMsg();
        }
        if (jobLog.getHandleCode() > 0 && jobLog.getHandleCode() != ReturnT.SUCCESS_CODE) {
            alarmContent += "<br>HandleCode=" + jobLog.getHandleMsg();
        }

        Set<String> emailSet = new HashSet<String>(Arrays.asList(info.getAlarmEmail().split(",")));
        for (String email : emailSet) {
            XxlJobGroup group = XxlJobAdminConfig.getAdminConfig().getXxlJobGroupDao().load(Integer.valueOf(info.getJobGroup()));

            String title = I18nUtil.getString("jobconf_monitor");
            String content = MessageFormat.format(MAIL_BODY_TEMPLATE,
                    group != null ? group.getTitle() : "null",
                    info.getId(),
                    info.getJobDesc(),
                    alarmContent);

            MailUtil.sendMail(email, title, content);
        }
    }

    //  自定义报警策略, 如短信

}
 
Example 9
Source File: JobGroupController.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/update")
@ResponseBody
public ReturnT<String> update(XxlJobGroup xxlJobGroup){
	// valid
	if (xxlJobGroup.getAppName()==null || StringUtils.isBlank(xxlJobGroup.getAppName())) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input")+"AppName") );
	}
	if (xxlJobGroup.getAppName().length()<4 || xxlJobGroup.getAppName().length()>64) {
		return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_appName_length") );
	}
	if (xxlJobGroup.getTitle()==null || StringUtils.isBlank(xxlJobGroup.getTitle())) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")) );
	}
	if (xxlJobGroup.getAddressType() == 0) {
		// 0=自动注册
		List<String> registryList = findRegistryByAppName(xxlJobGroup.getAppName());
		String addressListStr = null;
		if (registryList!=null && !registryList.isEmpty()) {
			Collections.sort(registryList);
			addressListStr = StringUtils.join(registryList, ",");
		}
		xxlJobGroup.setAddressList(addressListStr);
	} else {
		// 1=手动录入
		if (StringUtils.isBlank(xxlJobGroup.getAddressList())) {
			return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
		}
		String[] addresss = xxlJobGroup.getAddressList().split(",");
		for (String item: addresss) {
			if (StringUtils.isBlank(item)) {
				return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
			}
		}
	}

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

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

	int ret = xxlJobGroupDao.save(xxlJobGroup);
	return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
}
 
Example 11
Source File: JobLogController.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/logKill")
@ResponseBody
public ReturnT<String> logKill(Integer id) {
    // base check
    XxlJobLog log = xxlJobLogDao.load(id);
    XxlJobInfo jobInfo = xxlJobInfoDao.loadById(log.getJobId());
    if (jobInfo == null) {
        return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
    }
    if (ReturnT.SUCCESS_CODE != log.getTriggerCode()) {
        return new ReturnT<String>(500, I18nUtil.getString("joblog_kill_log_limit"));
    }

    // request of kill
    ReturnT<String> runResult = null;
    try {
        ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(log.getExecutorAddress());
        runResult = executorBiz.kill(jobInfo.getId());
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        runResult = new ReturnT<String>(500, e.getMessage());
    }

    if (ReturnT.SUCCESS_CODE == runResult.getCode()) {
        log.setHandleCode(ReturnT.FAIL_CODE);
        log.setHandleMsg(I18nUtil.getString("joblog_kill_log_byman") + ":" + (runResult.getMsg() != null ? runResult.getMsg() : ""));
        log.setHandleTime(new Date());
        xxlJobLogDao.updateHandleInfo(log);
        return new ReturnT<String>(runResult.getMsg());
    } else {
        return new ReturnT<String>(500, runResult.getMsg());
    }
}
 
Example 12
Source File: JobLogController.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/logKill")
@ResponseBody
public ReturnT<String> logKill(Integer id) {
    // base check
    XxlJobLog log = xxlJobLogDao.load(id);
    XxlJobInfo jobInfo = xxlJobInfoDao.loadById(log.getJobId());
    if (jobInfo == null) {
        return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
    }
    if (ReturnT.SUCCESS_CODE != log.getTriggerCode()) {
        return new ReturnT<String>(500, I18nUtil.getString("joblog_kill_log_limit"));
    }

    // request of kill
    ReturnT<String> runResult = null;
    try {
        ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(log.getExecutorAddress());
        runResult = executorBiz.kill(jobInfo.getId());
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        runResult = new ReturnT<String>(500, e.getMessage());
    }

    if (ReturnT.SUCCESS_CODE == runResult.getCode()) {
        log.setHandleCode(ReturnT.FAIL_CODE);
        log.setHandleMsg(I18nUtil.getString("joblog_kill_log_byman") + ":" + (runResult.getMsg() != null ? runResult.getMsg() : ""));
        log.setHandleTime(new Date());
        xxlJobLogDao.updateHandleInfo(log);
        return new ReturnT<String>(runResult.getMsg());
    } else {
        return new ReturnT<String>(500, runResult.getMsg());
    }
}
 
Example 13
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 14
Source File: JobGroupController.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/save")
@ResponseBody
public ReturnT<String> save(XxlJobGroup xxlJobGroup){

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

	int ret = xxlJobGroupDao.save(xxlJobGroup);
	return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
}
 
Example 15
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 16
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 17
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 18
Source File: JobFailMonitorHelper.java    From zuihou-admin-boot with Apache License 2.0 4 votes vote down vote up
public void start() {
    monitorThread = new Thread(new Runnable() {

        @Override
        public void run() {
            // monitor
            while (!toStop) {
                try {
                    List<Integer> jobLogIdList = new ArrayList<Integer>();
                    //一次性从BlockingQueue获取所有可用的数据对象(还可以指定获取数据的个数),
                    //    通过该方法,可以提升获取数据效率;不需要多次分批加锁或释放锁。
                    int drainToNum = JobFailMonitorHelper.instance.queue.drainTo(jobLogIdList);

                    if (CollectionUtils.isNotEmpty(jobLogIdList)) {
                        for (Integer jobLogId : jobLogIdList) {
                            if (jobLogId == null || jobLogId == 0) {
                                continue;
                            }
                            XxlJobLog log = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().load(jobLogId);
                            if (log == null) {
                                continue;
                            }
				/*
				 判断执行成功的字段有2个,xxl_job_qrtz_trigger_log 表的TriggerCode=调度器调度状态 、HandleCode=执行器执行状态

				  */
                            if (IJobHandler.SUCCESS.getCode() == log.getTriggerCode() && log.getHandleCode() == 0) {
                                // job running
                                JobFailMonitorHelper.monitor(jobLogId);
                                logger.debug(">>>>>>>>>>> job monitor, job running, JobLogId:{}", jobLogId);
                            } else if (IJobHandler.SUCCESS.getCode() == log.getHandleCode()) {
                                // job success, pass
                                logger.info(">>>>>>>>>>> job monitor, job success, JobLogId:{}", jobLogId);
                            } else /*if (IJobHandler.FAIL.getCode() == log.getTriggerCode()
						|| IJobHandler.FAIL.getCode() == log.getHandleCode()
						|| IJobHandler.FAIL_RETRY.getCode() == log.getHandleCode() )*/ {

                                // job fail,

                                // 1、fail retry
                                XxlJobInfo info = XxlJobAdminConfig.getAdminConfig().getXxlJobInfoDao().loadById(log.getJobId());

                                if (log.getExecutorFailRetryCount() > 0) {
                                    JobTriggerPoolHelper.trigger(log.getJobId(), TriggerTypeEnum.RETRY, (log.getExecutorFailRetryCount() - 1), log.getExecutorShardingParam(), null);
                                    String retryMsg = "<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>" + I18nUtil.getString("jobconf_trigger_type_retry") + "<<<<<<<<<<< </span><br>";
                                    log.setTriggerMsg(log.getTriggerMsg() + retryMsg);
                                    XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateTriggerInfo(log);
                                }

                                // 2、fail alarm
                                failAlarm(info, log);

                                logger.info(">>>>>>>>>>> job monitor, job fail, JobLogId:{}", jobLogId);
                            }/* else {
					JobFailMonitorHelper.monitor(jobLogId);
					logger.info(">>>>>>>>>>> job monitor, job status unknown, JobLogId:{}", jobLogId);
				}*/
                        }
                    }

                    TimeUnit.SECONDS.sleep(10);
                } catch (Exception e) {
                    logger.error("job monitor error:{}", e);
                }
            }

            // monitor all clear
            List<Integer> jobLogIdList = new ArrayList<Integer>();
            int drainToNum = getInstance().queue.drainTo(jobLogIdList);
            if (jobLogIdList != null && jobLogIdList.size() > 0) {
                for (Integer jobLogId : jobLogIdList) {
                    XxlJobLog log = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().load(jobLogId);
                    if (ReturnT.FAIL_CODE == log.getTriggerCode() || ReturnT.FAIL_CODE == log.getHandleCode()) {
                        // job fail,
                        XxlJobInfo info = XxlJobAdminConfig.getAdminConfig().getXxlJobInfoDao().loadById(log.getJobId());

                        failAlarm(info, log);
                        logger.info(">>>>>>>>>>> job monitor last, job fail, JobLogId:{}", jobLogId);
                    }
                }
            }

        }
    });
    monitorThread.setDaemon(true);//守护线程
    monitorThread.start();
}
 
Example 19
Source File: XxlJobServiceImpl.java    From zuihou-admin-boot with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnT<String> update(XxlJobInfo jobInfo) {

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

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

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

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

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

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

    return ReturnT.SUCCESS;
}
 
Example 20
Source File: JobFailMonitorHelper.java    From microservices-platform with Apache License 2.0 4 votes vote down vote up
public void start(){
	monitorThread = new Thread(new Runnable() {

		@Override
		public void run() {

			// monitor
			while (!toStop) {
				try {

					List<Integer> failLogIds = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findFailJobLogIds(1000);
					if (failLogIds!=null && !failLogIds.isEmpty()) {
						for (int failLogId: failLogIds) {

							// lock log
							int lockRet = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateAlarmStatus(failLogId, 0, -1);
							if (lockRet < 1) {
								continue;
							}
							XxlJobLog log = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().load(failLogId);
							XxlJobInfo info = XxlJobAdminConfig.getAdminConfig().getXxlJobInfoDao().loadById(log.getJobId());

							// 1、fail retry monitor
							if (log.getExecutorFailRetryCount() > 0) {
								JobTriggerPoolHelper.trigger(log.getJobId(), TriggerTypeEnum.RETRY, (log.getExecutorFailRetryCount()-1), log.getExecutorShardingParam(), null);
								String retryMsg = "<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_type_retry") +"<<<<<<<<<<< </span><br>";
								log.setTriggerMsg(log.getTriggerMsg() + retryMsg);
								XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateTriggerInfo(log);
							}

							// 2、fail alarm monitor
							int newAlarmStatus = 0;		// 告警状态:0-默认、-1=锁定状态、1-无需告警、2-告警成功、3-告警失败
							if (info!=null && info.getAlarmEmail()!=null && info.getAlarmEmail().trim().length()>0) {
								boolean alarmResult = true;
								try {
									alarmResult = failAlarm(info, log);
								} catch (Exception e) {
									alarmResult = false;
									logger.error(e.getMessage(), e);
								}
								newAlarmStatus = alarmResult?2:3;
							} else {
								newAlarmStatus = 1;
							}

							XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateAlarmStatus(failLogId, -1, newAlarmStatus);
						}
					}

					TimeUnit.SECONDS.sleep(10);
				} catch (Exception e) {
					if (!toStop) {
						logger.error(">>>>>>>>>>> xxl-job, job fail monitor thread error:{}", e);
					}
				}
			}

			logger.info(">>>>>>>>>>> xxl-job, job fail monitor thread stop");

		}
	});
	monitorThread.setDaemon(true);
	monitorThread.start();
}