com.xxl.job.admin.core.model.XxlJobInfo Java Examples

The following examples show how to use com.xxl.job.admin.core.model.XxlJobInfo. 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: XxlJobServiceImpl.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Object> pageList(Integer start, Integer length, Integer jobGroup, String jobDesc, String executorHandler, String filterTime, Integer type) {

    // page list
    List<XxlJobInfo> list = xxlJobInfoDao.pageList(start, length, jobGroup, jobDesc, executorHandler, type);
    int listCount = xxlJobInfoDao.pageListCount(start, length, jobGroup, jobDesc, executorHandler, type);

    // fill job info
    if (list != null && list.size() > 0) {
        for (XxlJobInfo jobInfo : list) {
            XxlJobDynamicScheduler.fillJobInfo(jobInfo);
        }
    }

    // package result
    Map<String, Object> maps = new HashMap<String, Object>();
    maps.put("recordsTotal", listCount);        // 总记录数
    maps.put("recordsFiltered", listCount);    // 过滤后的总记录数
    maps.put("data", list);                    // 分页列表
    return maps;
}
 
Example #2
Source File: JobFailMonitorHelper.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
/**
 * fail alarm
 *
 * @param jobLog
 */
private void failAlarm(XxlJobLog jobLog){

	// 发送监控的邮件
	XxlJobInfo info = XxlJobDynamicScheduler.xxlJobInfoDao.loadById(jobLog.getJobId());
	if (info!=null && info.getAlarmEmail()!=null && info.getAlarmEmail().trim().length()>0) {

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

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

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

	// TODO, custom alarm strategy, such as sms

}
 
Example #3
Source File: JobCodeController.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
@RequestMapping
public String index(Model model, Integer jobId) {
    XxlJobInfo jobInfo = xxlJobInfoDao.loadById(jobId);
    List<XxlJobLogGlue> jobLogGlues = xxlJobLogGlueDao.findByJobId(jobId);

    if (jobInfo == null) {
        throw new RuntimeException(I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
    }
    if (GlueTypeEnum.BEAN == GlueTypeEnum.match(jobInfo.getGlueType())) {
        throw new RuntimeException(I18nUtil.getString("jobinfo_glue_gluetype_unvalid"));
    }

    // Glue类型-字典
    model.addAttribute("GlueTypeEnum", GlueTypeEnum.values());

    model.addAttribute("jobInfo", jobInfo);
    model.addAttribute("jobLogGlues", jobLogGlues);
    return "jobcode/jobcode.index";
}
 
Example #4
Source File: JobCodeController.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
@RequestMapping
public String index(Model model, Integer jobId) {
    XxlJobInfo jobInfo = xxlJobInfoDao.loadById(jobId);
    List<XxlJobLogGlue> jobLogGlues = xxlJobLogGlueDao.findByJobId(jobId);

    if (jobInfo == null) {
        throw new RuntimeException(I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
    }
    if (GlueTypeEnum.BEAN == GlueTypeEnum.match(jobInfo.getGlueType())) {
        throw new RuntimeException(I18nUtil.getString("jobinfo_glue_gluetype_unvalid"));
    }

    // Glue类型-字典
    model.addAttribute("GlueTypeEnum", GlueTypeEnum.values());

    model.addAttribute("jobInfo", jobInfo);
    model.addAttribute("jobLogGlues", jobLogGlues);
    return "jobcode/jobcode.index";
}
 
Example #5
Source File: XxlJobServiceImpl.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnT<String> triggerJob(int id) {
       XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
       if (xxlJobInfo == null) {
       	return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString("system_unvalid")) );
	}

       String group = String.valueOf(xxlJobInfo.getJobGroup());
       String name = String.valueOf(xxlJobInfo.getId());

	try {
		XxlJobDynamicScheduler.triggerJob(name, group);
		return ReturnT.SUCCESS;
	} catch (SchedulerException e) {
		logger.error(e.getMessage(), e);
		return new ReturnT<String>(ReturnT.FAIL_CODE, e.getMessage());
	}
}
 
Example #6
Source File: XxlJobServiceImpl.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnT<String> remove(Integer id) {
    XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
    String group = String.valueOf(xxlJobInfo.getJobGroup());
    String name = String.valueOf(xxlJobInfo.getId());

    try {
        // unbind quartz
        XxlJobDynamicScheduler.removeJob(name, group);

        xxlJobInfoDao.delete(id);
        xxlJobLogDao.delete(id);
        xxlJobLogGlueDao.deleteByJobId(id);
        return ReturnT.SUCCESS;
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        return ReturnT.FAIL;
    }
}
 
Example #7
Source File: XxlJobServiceImpl.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnT<String> remove(int id) {
	XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
       String group = String.valueOf(xxlJobInfo.getJobGroup());
       String name = String.valueOf(xxlJobInfo.getId());

	try {
		XxlJobDynamicScheduler.removeJob(name, group);
		xxlJobInfoDao.delete(id);
		xxlJobLogDao.delete(id);
		xxlJobLogGlueDao.deleteByJobId(id);
		return ReturnT.SUCCESS;
	} catch (SchedulerException e) {
		logger.error(e.getMessage(), e);
	}
	return ReturnT.FAIL;
}
 
Example #8
Source File: JobCodeController.java    From xxl-job with GNU General Public License v3.0 6 votes vote down vote up
@RequestMapping
public String index(HttpServletRequest request, Model model, int jobId) {
	XxlJobInfo jobInfo = xxlJobInfoDao.loadById(jobId);
	List<XxlJobLogGlue> jobLogGlues = xxlJobLogGlueDao.findByJobId(jobId);

	if (jobInfo == null) {
		throw new RuntimeException(I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
	}
	if (GlueTypeEnum.BEAN == GlueTypeEnum.match(jobInfo.getGlueType())) {
		throw new RuntimeException(I18nUtil.getString("jobinfo_glue_gluetype_unvalid"));
	}

	// valid permission
	JobInfoController.validPermission(request, jobInfo.getJobGroup());

	// Glue类型-字典
	model.addAttribute("GlueTypeEnum", GlueTypeEnum.values());

	model.addAttribute("jobInfo", jobInfo);
	model.addAttribute("jobLogGlues", jobLogGlues);
	return "jobcode/jobcode.index";
}
 
Example #9
Source File: XxlJobServiceImpl.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnT<String> remove(Integer id) {
    XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
    String group = String.valueOf(xxlJobInfo.getJobGroup());
    String name = String.valueOf(xxlJobInfo.getId());

    try {
        // unbind quartz
        XxlJobDynamicScheduler.removeJob(name, group);

        xxlJobInfoDao.delete(id);
        xxlJobLogDao.delete(id);
        xxlJobLogGlueDao.deleteByJobId(id);
        return ReturnT.SUCCESS;
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        return ReturnT.FAIL;
    }
}
 
Example #10
Source File: JobLogController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@RequestMapping
public String index(Model model, @RequestParam(required = false, defaultValue = "0") Integer jobId) {

	// 执行器列表
	List<XxlJobGroup> jobGroupList =  xxlJobGroupDao.findAll();
	model.addAttribute("JobGroupList", jobGroupList);
	model.addAttribute("GlueTypeEnum", GlueTypeEnum.values());

	// 任务
	if (jobId > 0) {
		XxlJobInfo jobInfo = xxlJobInfoDao.loadById(jobId);
		model.addAttribute("jobInfo", jobInfo);
	}

	return "joblog/joblog.index";
}
 
Example #11
Source File: XxlJobServiceImpl.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Object> pageList(int start, int length, int jobGroup, String jobDesc, String executorHandler, String filterTime) {

	// page list
	List<XxlJobInfo> list = xxlJobInfoDao.pageList(start, length, jobGroup, jobDesc, executorHandler);
	int list_count = xxlJobInfoDao.pageListCount(start, length, jobGroup, jobDesc, executorHandler);
	
	// fill job info
	if (list!=null && list.size()>0) {
		for (XxlJobInfo jobInfo : list) {
			XxlJobDynamicScheduler.fillJobInfo(jobInfo);
		}
	}
	
	// package result
	Map<String, Object> maps = new HashMap<String, Object>();
    maps.put("recordsTotal", list_count);		// 总记录数
    maps.put("recordsFiltered", list_count);	// 过滤后的总记录数
    maps.put("data", list);  					// 分页列表
	return maps;
}
 
Example #12
Source File: XxlJobServiceImpl.java    From zuihou-admin-boot 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 #13
Source File: JobLogController.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
@RequestMapping
public String index(Model model, @RequestParam(required = false, defaultValue = "0") Integer jobId) {

    // 执行器列表
    List<XxlJobGroup> jobGroupList = xxlJobGroupDao.findAll();
    model.addAttribute("JobGroupList", jobGroupList);

    // 任务
    if (jobId > 0) {
        XxlJobInfo jobInfo = xxlJobInfoDao.loadById(jobId);
        model.addAttribute("jobInfo", jobInfo);
    }

    return "joblog/joblog.index";
}
 
Example #14
Source File: XxlJobServiceImpl.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> pause(int id) {
       XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
       String group = String.valueOf(xxlJobInfo.getJobGroup());
       String name = String.valueOf(xxlJobInfo.getId());

	try {
           boolean ret = XxlJobDynamicScheduler.pauseJob(name, group);	// jobStatus do not store
           return ret?ReturnT.SUCCESS:ReturnT.FAIL;
	} catch (SchedulerException e) {
		logger.error(e.getMessage(), e);
		return ReturnT.FAIL;
	}
}
 
Example #15
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 #16
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 #17
Source File: XxlJobServiceImpl.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> addStart(XxlJobInfo jobInfo) {
    ReturnT<String> result = this.add(jobInfo);
    if (result.getIsSuccess()) {
        start(Integer.valueOf(result.getContent()));
    }
    return result;
}
 
Example #18
Source File: JobLogController.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/logKill")
@ResponseBody
public ReturnT<String> logKill(int 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 #19
Source File: JobFailMonitorHelper.java    From zuihou-admin-cloud 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 #20
Source File: XxlJobServiceImpl.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ReturnT<String> stop(int id) {
       XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);

	xxlJobInfo.setTriggerStatus(0);
	xxlJobInfo.setTriggerLastTime(0);
	xxlJobInfo.setTriggerNextTime(0);

	xxlJobInfo.setUpdateTime(new Date());
	xxlJobInfoDao.update(xxlJobInfo);
	return ReturnT.SUCCESS;
}
 
Example #21
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 #22
Source File: XxlJobServiceImpl.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> stop(int id) {
       XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
       String group = String.valueOf(xxlJobInfo.getJobGroup());
       String name = String.valueOf(xxlJobInfo.getId());

	try {
		// bind quartz
           boolean ret = XxlJobDynamicScheduler.removeJob(name, group);
           return ret?ReturnT.SUCCESS:ReturnT.FAIL;
	} catch (SchedulerException e) {
		logger.error(e.getMessage(), e);
		return ReturnT.FAIL;
	}
}
 
Example #23
Source File: JobLogController.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/logKill")
@ResponseBody
public ReturnT<String> logKill(int 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 #24
Source File: XxlJobDynamicScheduler.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
/**
    * fill job info
    *
    * @param jobInfo
    */
public static void fillJobInfo(XxlJobInfo jobInfo) {

       String group = String.valueOf(jobInfo.getJobGroup());
       String name = String.valueOf(jobInfo.getId());

       // trigger key
       TriggerKey triggerKey = TriggerKey.triggerKey(name, group);
       try {

           // trigger cron
		Trigger trigger = scheduler.getTrigger(triggerKey);
		if (trigger!=null && trigger instanceof CronTriggerImpl) {
			String cronExpression = ((CronTriggerImpl) trigger).getCronExpression();
			jobInfo.setJobCron(cronExpression);
		}

           // trigger state
           TriggerState triggerState = scheduler.getTriggerState(triggerKey);
		if (triggerState!=null) {
			jobInfo.setJobStatus(triggerState.name());
		}

           //JobKey jobKey = new JobKey(jobInfo.getJobName(), String.valueOf(jobInfo.getJobGroup()));
           //JobDetail jobDetail = scheduler.getJobDetail(jobKey);
           //String jobClass = jobDetail.getJobClass().getName();
		
	} catch (SchedulerException e) {
		logger.error(e.getMessage(), e);
	}
}
 
Example #25
Source File: XxlJobInfoDao.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
public List<XxlJobInfo> pageList(@Param("offset") int offset,
@Param("pagesize") int pagesize,
@Param("jobGroup") int jobGroup,
@Param("triggerStatus") int triggerStatus,
@Param("jobDesc") String jobDesc,
@Param("executorHandler") String executorHandler,
@Param("author") String author);
 
Example #26
Source File: JobLogController.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping("/logKill")
@ResponseBody
public ReturnT<String> logKill(int 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 = XxlJobScheduler.getExecutorBiz(log.getExecutorAddress());
		runResult = executorBiz.kill(new KillParam(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 #27
Source File: JobCodeController.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/save")
@ResponseBody
public ReturnT<String> save(Model model, Integer 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 existsJobinfo = xxlJobInfoDao.loadById(id);
    if (existsJobinfo == null) {
        return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
    }

    // update new code
    existsJobinfo.setGlueSource(glueSource);
    existsJobinfo.setGlueRemark(glueRemark);
    existsJobinfo.setGlueUpdatetime(new Date());
    xxlJobInfoDao.update(existsJobinfo);

    // log old code
    XxlJobLogGlue xxlJobLogGlue = new XxlJobLogGlue();
    xxlJobLogGlue.setJobId(existsJobinfo.getId());
    xxlJobLogGlue.setGlueType(existsJobinfo.getGlueType());
    xxlJobLogGlue.setGlueSource(glueSource);
    xxlJobLogGlue.setGlueRemark(glueRemark);
    xxlJobLogGlueDao.save(xxlJobLogGlue);

    // remove code backup more than 30
    xxlJobLogGlueDao.removeOld(existsJobinfo.getId(), 30);

    return ReturnT.SUCCESS;
}
 
Example #28
Source File: XxlJobDynamicScheduler.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * fill job info
 *
 * @param jobInfo
 */
public static void fillJobInfo(XxlJobInfo jobInfo) {

    String group = String.valueOf(jobInfo.getJobGroup());
    String name = String.valueOf(jobInfo.getId());

    // trigger key
    TriggerKey triggerKey = TriggerKey.triggerKey(name, group);
    try {

        // trigger cron
        Trigger trigger = scheduler.getTrigger(triggerKey);
        if (trigger != null && trigger instanceof CronTriggerImpl) {
            String cronExpression = ((CronTriggerImpl) trigger).getCronExpression();
            jobInfo.setJobCron(cronExpression);
        }

        // trigger state
        TriggerState triggerState = scheduler.getTriggerState(triggerKey);
        if (triggerState != null) {
            jobInfo.setJobStatus(triggerState.name());
        }

    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example #29
Source File: XxlJobTrigger.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
/**
 * trigger job
 *
 * @param jobId
 * @param triggerType
 * @param failRetryCount
 * 			>=0: use this param
 * 			<0: use param from job info config
 * @param executorShardingParam
 * @param executorParam
 *          null: use job param
 *          not null: cover job param
 */
public static void trigger(int jobId, TriggerTypeEnum triggerType, int failRetryCount, String executorShardingParam, String executorParam) {
    // load data
    XxlJobInfo jobInfo = XxlJobAdminConfig.getAdminConfig().getXxlJobInfoDao().loadById(jobId);
    if (jobInfo == null) {
        logger.warn(">>>>>>>>>>>> trigger fail, jobId invalid,jobId={}", jobId);
        return;
    }
    if (executorParam != null) {
        jobInfo.setExecutorParam(executorParam);
    }
    int finalFailRetryCount = failRetryCount>=0?failRetryCount:jobInfo.getExecutorFailRetryCount();
    XxlJobGroup group = XxlJobAdminConfig.getAdminConfig().getXxlJobGroupDao().load(jobInfo.getJobGroup());

    // sharding param
    int[] shardingParam = null;
    if (executorShardingParam!=null){
        String[] shardingArr = executorShardingParam.split("/");
        if (shardingArr.length==2 && StringUtils.isNumeric(shardingArr[0]) && StringUtils.isNumeric(shardingArr[1])) {
            shardingParam = new int[2];
            shardingParam[0] = Integer.valueOf(shardingArr[0]);
            shardingParam[1] = Integer.valueOf(shardingArr[1]);
        }
    }
    if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST==ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null)
            && group.getRegistryList()!=null && !group.getRegistryList().isEmpty()
            && shardingParam==null) {
        for (int i = 0; i < group.getRegistryList().size(); i++) {
            processTrigger(group, jobInfo, finalFailRetryCount, triggerType, i, group.getRegistryList().size());
        }
    } else {
        if (shardingParam == null) {
            shardingParam = new int[]{0, 1};
        }
        processTrigger(group, jobInfo, finalFailRetryCount, triggerType, shardingParam[0], shardingParam[1]);
    }

}
 
Example #30
Source File: XxlJobServiceImpl.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> stop(Integer id) {
    XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
    String group = String.valueOf(xxlJobInfo.getJobGroup());
    String name = String.valueOf(xxlJobInfo.getId());

    try {
        // bind quartz
        boolean ret = XxlJobDynamicScheduler.removeJob(name, group);
        return ret ? ReturnT.SUCCESS : ReturnT.FAIL;
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        return ReturnT.FAIL;
    }
}