Search in sources :

Example 11 with ReturnT

use of com.xxl.job.core.biz.model.ReturnT in project xxl-job by xuxueli.

the class ExecutorRouteBusyover method routeRun.

@Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<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);
        }
        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) {
            ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
            idleBeatResultSB.append("<br><br>").append(runResult.getMsg());
            // result
            runResult.setMsg(idleBeatResultSB.toString());
            runResult.setContent(address);
            return runResult;
        }
    }
    return new ReturnT<String>(ReturnT.FAIL_CODE, idleBeatResultSB.toString());
}
Also used : ExecutorBiz(com.xxl.job.core.biz.ExecutorBiz) ReturnT(com.xxl.job.core.biz.model.ReturnT)

Example 12 with ReturnT

use of com.xxl.job.core.biz.model.ReturnT in project xxl-job by xuxueli.

the class XxlJobServiceImpl method add.

@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());
    }
}
Also used : XxlJobGroup(com.xxl.job.admin.core.model.XxlJobGroup) SchedulerException(org.quartz.SchedulerException) ReturnT(com.xxl.job.core.biz.model.ReturnT) XxlJobInfo(com.xxl.job.admin.core.model.XxlJobInfo)

Example 13 with ReturnT

use of com.xxl.job.core.biz.model.ReturnT in project xxl-job by xuxueli.

the class XxlJobServiceImpl method update.

@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;
}
Also used : SchedulerException(org.quartz.SchedulerException) ReturnT(com.xxl.job.core.biz.model.ReturnT) XxlJobInfo(com.xxl.job.admin.core.model.XxlJobInfo)

Example 14 with ReturnT

use of com.xxl.job.core.biz.model.ReturnT in project xxl-job by xuxueli.

the class JobLogController method clearLog.

@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;
}
Also used : ReturnT(com.xxl.job.core.biz.model.ReturnT) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 15 with ReturnT

use of com.xxl.job.core.biz.model.ReturnT in project xxl-job by xuxueli.

the class ExecutorRouteFailover method routeRun.

@Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<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) {
            ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
            beatResultSB.append("<br><br>").append(runResult.getMsg());
            // result
            runResult.setMsg(beatResultSB.toString());
            runResult.setContent(address);
            return runResult;
        }
    }
    return new ReturnT<String>(ReturnT.FAIL_CODE, beatResultSB.toString());
}
Also used : ExecutorBiz(com.xxl.job.core.biz.ExecutorBiz) ReturnT(com.xxl.job.core.biz.model.ReturnT)

Aggregations

ReturnT (com.xxl.job.core.biz.model.ReturnT)16 XxlJobInfo (com.xxl.job.admin.core.model.XxlJobInfo)7 Date (java.util.Date)7 ExecutorBiz (com.xxl.job.core.biz.ExecutorBiz)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 XxlJobLog (com.xxl.job.admin.core.model.XxlJobLog)3 SchedulerException (org.quartz.SchedulerException)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 XxlJobGroup (com.xxl.job.admin.core.model.XxlJobGroup)2 TriggerParam (com.xxl.job.core.biz.model.TriggerParam)2 ExecutorBlockStrategyEnum (com.xxl.job.core.enums.ExecutorBlockStrategyEnum)2 JobThread (com.xxl.job.core.thread.JobThread)2 ExecutorFailStrategyEnum (com.xxl.job.admin.core.enums.ExecutorFailStrategyEnum)1 XxlJobLogGlue (com.xxl.job.admin.core.model.XxlJobLogGlue)1 ExecutorRouteStrategyEnum (com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum)1 HandleCallbackParam (com.xxl.job.core.biz.model.HandleCallbackParam)1 LogResult (com.xxl.job.core.biz.model.LogResult)1 GlueTypeEnum (com.xxl.job.core.glue.GlueTypeEnum)1 IJobHandler (com.xxl.job.core.handler.IJobHandler)1 GlueJobHandler (com.xxl.job.core.handler.impl.GlueJobHandler)1