Java Code Examples for com.xxl.job.core.biz.model.ReturnT#FAIL_CODE

The following examples show how to use com.xxl.job.core.biz.model.ReturnT#FAIL_CODE . 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 open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/logDetailCat")
@ResponseBody
public ReturnT<LogResult> logDetailCat(String executorAddress, long triggerTime, int logId, int fromLineNum){
	try {
		ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(executorAddress);
		ReturnT<LogResult> logResult = executorBiz.log(triggerTime, logId, fromLineNum);

		// is end
           if (logResult.getContent()!=null && logResult.getContent().getFromLineNum() > logResult.getContent().getToLineNum()) {
               XxlJobLog jobLog = xxlJobLogDao.load(logId);
               if (jobLog.getHandleCode() > 0) {
                   logResult.getContent().setEnd(true);
               }
           }

		return logResult;
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		return new ReturnT<LogResult>(ReturnT.FAIL_CODE, e.getMessage());
	}
}
 
Example 2
Source File: JobLogController.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/logDetailCat")
@ResponseBody
public ReturnT<LogResult> logDetailCat(String executorAddress, long triggerTime, int logId, int fromLineNum){
	try {
		ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(executorAddress);
		ReturnT<LogResult> logResult = executorBiz.log(triggerTime, logId, fromLineNum);

		// is end
           if (logResult.getContent()!=null && logResult.getContent().getFromLineNum() > logResult.getContent().getToLineNum()) {
               XxlJobLog jobLog = xxlJobLogDao.load(logId);
               if (jobLog.getHandleCode() > 0) {
                   logResult.getContent().setEnd(true);
               }
           }

		return logResult;
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		return new ReturnT<LogResult>(ReturnT.FAIL_CODE, e.getMessage());
	}
}
 
Example 3
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 4
Source File: UserController.java    From xxl-job with GNU General Public License v3.0 6 votes vote down vote up
@RequestMapping("/updatePwd")
@ResponseBody
public ReturnT<String> updatePwd(HttpServletRequest request, String password){

    // valid password
    if (password==null || password.trim().length()==0){
        return new ReturnT<String>(ReturnT.FAIL.getCode(), "密码不可为空");
    }
    password = password.trim();
    if (!(password.length()>=4 && password.length()<=20)) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("system_lengh_limit")+"[4-20]" );
    }

    // md5 password
    String md5Password = DigestUtils.md5DigestAsHex(password.getBytes());

    // update pwd
    XxlJobUser loginUser = (XxlJobUser) request.getAttribute(LoginService.LOGIN_IDENTITY_KEY);

    // do write
    XxlJobUser existUser = xxlJobUserDao.loadByUserName(loginUser.getUsername());
    existUser.setPassword(md5Password);
    xxlJobUserDao.update(existUser);

    return ReturnT.SUCCESS;
}
 
Example 5
Source File: ExecutorRouteBusyover.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {
    StringBuffer idleBeatResultSB = new StringBuffer();
    for (String address : addressList) {
        // beat
        ReturnT<String> idleBeatResult = null;
        try {
            ExecutorBiz executorBiz = XxlJobScheduler.getExecutorBiz(address);
            idleBeatResult = executorBiz.idleBeat(new IdleBeatParam(triggerParam.getJobId()));
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            idleBeatResult = new ReturnT<String>(ReturnT.FAIL_CODE, ""+e );
        }
        idleBeatResultSB.append( (idleBeatResultSB.length()>0)?"<br><br>":"")
                .append(I18nUtil.getString("jobconf_idleBeat") + ":")
                .append("<br>address:").append(address)
                .append("<br>code:").append(idleBeatResult.getCode())
                .append("<br>msg:").append(idleBeatResult.getMsg());

        // beat success
        if (idleBeatResult.getCode() == ReturnT.SUCCESS_CODE) {
            idleBeatResult.setMsg(idleBeatResultSB.toString());
            idleBeatResult.setContent(address);
            return idleBeatResult;
        }
    }

    return new ReturnT<String>(ReturnT.FAIL_CODE, idleBeatResultSB.toString());
}
 
Example 6
Source File: UserController.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping("/update")
@ResponseBody
@PermissionLimit(adminuser = true)
public ReturnT<String> update(HttpServletRequest request, XxlJobUser xxlJobUser) {

    // avoid opt login seft
    XxlJobUser loginUser = (XxlJobUser) request.getAttribute(LoginService.LOGIN_IDENTITY_KEY);
    if (loginUser.getUsername().equals(xxlJobUser.getUsername())) {
        return new ReturnT<String>(ReturnT.FAIL.getCode(), I18nUtil.getString("user_update_loginuser_limit"));
    }

    // valid password
    if (StringUtils.hasText(xxlJobUser.getPassword())) {
        xxlJobUser.setPassword(xxlJobUser.getPassword().trim());
        if (!(xxlJobUser.getPassword().length()>=4 && xxlJobUser.getPassword().length()<=20)) {
            return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("system_lengh_limit")+"[4-20]" );
        }
        // md5 password
        xxlJobUser.setPassword(DigestUtils.md5DigestAsHex(xxlJobUser.getPassword().getBytes()));
    } else {
        xxlJobUser.setPassword(null);
    }

    // write
    xxlJobUserDao.update(xxlJobUser);
    return ReturnT.SUCCESS;
}
 
Example 7
Source File: ExecutorRouteFailover.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {

    StringBuffer beatResultSB = new StringBuffer();
    for (String address : addressList) {
        // beat
        ReturnT<String> beatResult = null;
        try {
            ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(address);
            beatResult = executorBiz.beat();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            beatResult = new ReturnT<String>(ReturnT.FAIL_CODE, "" + e);
        }
        beatResultSB.append((beatResultSB.length() > 0) ? "<br><br>" : "")
                .append(I18nUtil.getString("jobconf_beat") + ":")
                .append("<br>address:").append(address)
                .append("<br>code:").append(beatResult.getCode())
                .append("<br>msg:").append(beatResult.getMsg());

        // beat success
        if (beatResult.getCode() == ReturnT.SUCCESS_CODE) {

            beatResult.setMsg(beatResultSB.toString());
            beatResult.setContent(address);
            return beatResult;
        }
    }
    return new ReturnT<String>(ReturnT.FAIL_CODE, beatResultSB.toString());

}
 
Example 8
Source File: JobThread.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * new trigger to queue
 *
 * @param triggerParam
 * @return
 */
public ReturnT<String> pushTriggerQueue(TriggerParam triggerParam) {
    // avoid repeat
    if (triggerLogIdSet.contains(triggerParam.getLogId())) {
        logger.info(">>>>>>>>>>> repeate trigger job, logId:{}", triggerParam.getLogId());
        return new ReturnT<String>(ReturnT.FAIL_CODE, "repeate trigger job, logId:" + triggerParam.getLogId());
    }

    triggerLogIdSet.add(triggerParam.getLogId());
    triggerQueue.add(triggerParam);
    return ReturnT.SUCCESS;
}
 
Example 9
Source File: ExecutorRouteFailover.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {

    StringBuffer beatResultSB = new StringBuffer();
    for (String address : addressList) {
        // beat
        ReturnT<String> beatResult = null;
        try {
            ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(address);
            beatResult = executorBiz.beat();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            beatResult = new ReturnT<String>(ReturnT.FAIL_CODE, "" + e);
        }
        beatResultSB.append((beatResultSB.length() > 0) ? "<br><br>" : "")
                .append(I18nUtil.getString("jobconf_beat") + ":")
                .append("<br>address:").append(address)
                .append("<br>code:").append(beatResult.getCode())
                .append("<br>msg:").append(beatResult.getMsg());

        // beat success
        if (beatResult.getCode() == ReturnT.SUCCESS_CODE) {

            beatResult.setMsg(beatResultSB.toString());
            beatResult.setContent(address);
            return beatResult;
        }
    }
    return new ReturnT<String>(ReturnT.FAIL_CODE, beatResultSB.toString());

}
 
Example 10
Source File: ExecutorRouteFailover.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {

    StringBuffer beatResultSB = new StringBuffer();
    for (String address : addressList) {
        // beat
        ReturnT<String> beatResult = null;
        try {
            ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(address);
            beatResult = executorBiz.beat();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            beatResult = new ReturnT<String>(ReturnT.FAIL_CODE, ""+e );
        }
        beatResultSB.append( (beatResultSB.length()>0)?"<br><br>":"")
                .append(I18nUtil.getString("jobconf_beat") + ":")
                .append("<br>address:").append(address)
                .append("<br>code:").append(beatResult.getCode())
                .append("<br>msg:").append(beatResult.getMsg());

        // beat success
        if (beatResult.getCode() == ReturnT.SUCCESS_CODE) {

            beatResult.setMsg(beatResultSB.toString());
            beatResult.setContent(address);
            return beatResult;
        }
    }
    return new ReturnT<String>(ReturnT.FAIL_CODE, beatResultSB.toString());

}
 
Example 11
Source File: ExecutorRouteBusyover.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {
    StringBuffer idleBeatResultSB = new StringBuffer();
    for (String address : addressList) {
        // beat
        ReturnT<String> idleBeatResult = null;
        try {
            //
            ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(address);
            idleBeatResult = executorBiz.idleBeat(triggerParam.getJobId());
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            idleBeatResult = new ReturnT<String>(ReturnT.FAIL_CODE, "" + e);
        }
        //空闲检测:
        //address:
        //code:
        //msg:
        idleBeatResultSB.append((idleBeatResultSB.length() > 0) ? "<br><br>" : "")
                .append(I18nUtil.getString("jobconf_idleBeat") + ":")
                .append("<br>address:").append(address)
                .append("<br>code:").append(idleBeatResult.getCode())
                .append("<br>msg:").append(idleBeatResult.getMsg());

        // beat success
        if (idleBeatResult.getCode() == ReturnT.SUCCESS_CODE) {
            idleBeatResult.setMsg(idleBeatResultSB.toString());
            idleBeatResult.setContent(address);
            return idleBeatResult;
        }
    }

    return new ReturnT<String>(ReturnT.FAIL_CODE, idleBeatResultSB.toString());
}
 
Example 12
Source File: JobLogController.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/clearLog")
@ResponseBody
public ReturnT<String> clearLog(int jobGroup, int jobId, int type){

	Date clearBeforeTime = null;
	int clearBeforeNum = 0;
	if (type == 1) {
		clearBeforeTime = DateUtils.addMonths(new Date(), -1);	// 清理一个月之前日志数据
	} else if (type == 2) {
		clearBeforeTime = DateUtils.addMonths(new Date(), -3);	// 清理三个月之前日志数据
	} else if (type == 3) {
		clearBeforeTime = DateUtils.addMonths(new Date(), -6);	// 清理六个月之前日志数据
	} else if (type == 4) {
		clearBeforeTime = DateUtils.addYears(new Date(), -1);	// 清理一年之前日志数据
	} else if (type == 5) {
		clearBeforeNum = 1000;		// 清理一千条以前日志数据
	} else if (type == 6) {
		clearBeforeNum = 10000;		// 清理一万条以前日志数据
	} else if (type == 7) {
		clearBeforeNum = 30000;		// 清理三万条以前日志数据
	} else if (type == 8) {
		clearBeforeNum = 100000;	// 清理十万条以前日志数据
	} else if (type == 9) {
		clearBeforeNum = 0;			// 清理所有日志数据
	} else {
		return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("joblog_clean_type_unvalid"));
	}

	xxlJobLogDao.clearLog(jobGroup, jobId, clearBeforeTime, clearBeforeNum);
	return ReturnT.SUCCESS;
}
 
Example 13
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 14
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 15
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 16
Source File: JobGroupController.java    From xxl-job with GNU General Public License v3.0 4 votes vote down vote up
@RequestMapping("/loadById")
@ResponseBody
public ReturnT<XxlJobGroup> loadById(int id){
	XxlJobGroup jobGroup = xxlJobGroupDao.load(id);
	return jobGroup!=null?new ReturnT<XxlJobGroup>(jobGroup):new ReturnT<XxlJobGroup>(ReturnT.FAIL_CODE, null);
}
 
Example 17
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 18
Source File: AdminBizImpl.java    From zuihou-admin-cloud with Apache License 2.0 4 votes vote down vote up
private ReturnT<String> callback(HandleCallbackParam handleCallbackParam) {
    // valid log item
    XxlJobLog log = xxlJobLogDao.load(handleCallbackParam.getLogId());
    if (log == null) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, "log item not found.");
    }
    if (log.getHandleCode() > 0) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, "log repeate callback.");     // avoid repeat callback, trigger child job etc
    }

    // trigger success, to trigger child job
    String callbackMsg = null;
    if (IJobHandler.SUCCESS.getCode() == handleCallbackParam.getExecuteResult().getCode()) {
        XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(log.getJobId());
        if (xxlJobInfo != null && StringUtils.isNotBlank(xxlJobInfo.getChildJobId())) {
            callbackMsg = "<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>" + I18nUtil.getString("jobconf_trigger_child_run") + "<<<<<<<<<<< </span><br>";

            String[] childJobIds = xxlJobInfo.getChildJobId().split(",");
            for (int i = 0; i < childJobIds.length; i++) {
                int childJobId = (StringUtils.isNotBlank(childJobIds[i]) && StringUtils.isNumeric(childJobIds[i])) ? Integer.valueOf(childJobIds[i]) : -1;
                if (childJobId > 0) {

                    JobTriggerPoolHelper.trigger(childJobId, TriggerTypeEnum.PARENT, -1, null, null);
                    ReturnT<String> triggerChildResult = ReturnT.SUCCESS;

                    // add msg
                    callbackMsg += MessageFormat.format(I18nUtil.getString("jobconf_callback_child_msg1"),
                            (i + 1),
                            childJobIds.length,
                            childJobIds[i],
                            (triggerChildResult.getCode() == ReturnT.SUCCESS_CODE ? I18nUtil.getString("system_success") : I18nUtil.getString("system_fail")),
                            triggerChildResult.getMsg());
                } else {
                    callbackMsg += MessageFormat.format(I18nUtil.getString("jobconf_callback_child_msg2"),
                            (i + 1),
                            childJobIds.length,
                            childJobIds[i]);
                }
            }

        }
    }

    // handle msg
    StringBuffer handleMsg = new StringBuffer();
    if (log.getHandleMsg() != null) {
        handleMsg.append(log.getHandleMsg()).append("<br>");
    }
    if (handleCallbackParam.getExecuteResult().getMsg() != null) {
        handleMsg.append(handleCallbackParam.getExecuteResult().getMsg());
    }
    if (callbackMsg != null) {
        handleMsg.append(callbackMsg);
    }

    // success, save log
    log.setHandleTime(new Date());
    log.setHandleCode(handleCallbackParam.getExecuteResult().getCode());
    log.setHandleMsg(handleMsg.toString());
    xxlJobLogDao.updateHandleInfo(log);

    return ReturnT.SUCCESS;
}
 
Example 19
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 20
Source File: AdminBizImpl.java    From xxl-job with GNU General Public License v3.0 4 votes vote down vote up
private ReturnT<String> callback(HandleCallbackParam handleCallbackParam) {
    // valid log item
    XxlJobLog log = xxlJobLogDao.load(handleCallbackParam.getLogId());
    if (log == null) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, "log item not found.");
    }
    if (log.getHandleCode() > 0) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, "log repeate callback.");     // avoid repeat callback, trigger child job etc
    }

    // trigger success, to trigger child job
    String callbackMsg = null;
    if (IJobHandler.SUCCESS.getCode() == handleCallbackParam.getExecuteResult().getCode()) {
        XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(log.getJobId());
        if (xxlJobInfo!=null && xxlJobInfo.getChildJobId()!=null && xxlJobInfo.getChildJobId().trim().length()>0) {
            callbackMsg = "<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_child_run") +"<<<<<<<<<<< </span><br>";

            String[] childJobIds = xxlJobInfo.getChildJobId().split(",");
            for (int i = 0; i < childJobIds.length; i++) {
                int childJobId = (childJobIds[i]!=null && childJobIds[i].trim().length()>0 && isNumeric(childJobIds[i]))?Integer.valueOf(childJobIds[i]):-1;
                if (childJobId > 0) {

                    JobTriggerPoolHelper.trigger(childJobId, TriggerTypeEnum.PARENT, -1, null, null, null);
                    ReturnT<String> triggerChildResult = ReturnT.SUCCESS;

                    // add msg
                    callbackMsg += MessageFormat.format(I18nUtil.getString("jobconf_callback_child_msg1"),
                            (i+1),
                            childJobIds.length,
                            childJobIds[i],
                            (triggerChildResult.getCode()==ReturnT.SUCCESS_CODE?I18nUtil.getString("system_success"):I18nUtil.getString("system_fail")),
                            triggerChildResult.getMsg());
                } else {
                    callbackMsg += MessageFormat.format(I18nUtil.getString("jobconf_callback_child_msg2"),
                            (i+1),
                            childJobIds.length,
                            childJobIds[i]);
                }
            }

        }
    }

    // handle msg
    StringBuffer handleMsg = new StringBuffer();
    if (log.getHandleMsg()!=null) {
        handleMsg.append(log.getHandleMsg()).append("<br>");
    }
    if (handleCallbackParam.getExecuteResult().getMsg() != null) {
        handleMsg.append(handleCallbackParam.getExecuteResult().getMsg());
    }
    if (callbackMsg != null) {
        handleMsg.append(callbackMsg);
    }

    if (handleMsg.length() > 15000) {
        handleMsg = new StringBuffer(handleMsg.substring(0, 15000));  // text最大64kb 避免长度过长
    }

    // success, save log
    log.setHandleTime(new Date());
    log.setHandleCode(handleCallbackParam.getExecuteResult().getCode());
    log.setHandleMsg(handleMsg.toString());
    xxlJobLogDao.updateHandleInfo(log);

    return ReturnT.SUCCESS;
}