Java Code Examples for org.quartz.SchedulerException#getMessage()

The following examples show how to use org.quartz.SchedulerException#getMessage() . 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 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 2
Source File: ScheduleServiceImpl.java    From fixflow with Apache License 2.0 6 votes vote down vote up
public List<JobDetail> getJobList(String queryId){
	if(!getIsEnabled()){
		throw new FixFlowScheduleException(ExceptionCode.QUARZTEXCEPTION_ISENABLE);
	}
	Scheduler scheduler = getScheduler();
	List<JobDetail> jobList = new ArrayList<JobDetail>();
	Set<JobKey> set = new HashSet<JobKey>();
	try {
		//如果queryId不为空,则返回queryId对应的job,否则返回所有job
		if(StringUtil.isNotEmpty(queryId)){
			set = scheduler.getJobKeys(GroupMatcher.jobGroupContains(queryId));
		}else{
			List<String> groupNames = scheduler.getJobGroupNames();
			for(String groupName:groupNames){
				set.addAll(scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName)));
			}
		}
		for(JobKey key :set){
			JobDetail job = scheduler.getJobDetail(key); 
			jobList.add(job);
		}
	}catch (SchedulerException e) {
			throw new FixFlowException(e.getMessage(),e);
		}
	return jobList;
}
 
Example 3
Source File: ScheduleServiceImpl.java    From fixflow with Apache License 2.0 6 votes vote down vote up
public void schedulerRestart() {
	if(!getIsEnabled()){
		throw new FixFlowScheduleException(ExceptionCode.QUARZTEXCEPTION_ISENABLE);
	}
	Scheduler scheduler;
	try {
		scheduler = getScheduler();
		if(scheduler.isInStandbyMode()){
			scheduler.start();
		}else{
			scheduler.standby();
			scheduler.start();
		}
	} catch (SchedulerException e) {
		throw new FixFlowException(e.getMessage(),e);
	}
}
 
Example 4
Source File: SchedulerKernel.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Starts Taskomatic
 * This method does not return until the this.scheduler is shutdown
 * @throws TaskomaticException error occurred during Quartz or Hibernate startup
 */
public void startup() throws TaskomaticException {
    HibernateFactory.createSessionFactory(TASKOMATIC_PACKAGE_NAMES);
    if (!HibernateFactory.isInitialized()) {
        throw new TaskomaticException("HibernateFactory failed to initialize");
    }
    MessageQueue.startMessaging();
    MessageQueue.configureDefaultActions();
    try {
        SchedulerKernel.scheduler.start();
        initializeAllSatSchedules();
        synchronized (this.shutdownLock) {
            try {
                this.shutdownLock.wait();
            }
            catch (InterruptedException ignored) {
                return;
            }
        }
    }
    catch (SchedulerException e) {
        throw new TaskomaticException(e.getMessage(), e);
    }
}
 
Example 5
Source File: SchedulerKernel.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Starts Taskomatic
 * This method does not return until the this.scheduler is shutdown
 * @throws TaskomaticException error occurred during Quartz or Hibernate startup
 */
public void startup() throws TaskomaticException {
    HibernateFactory.createSessionFactory(TASKOMATIC_PACKAGE_NAMES);
    if (!HibernateFactory.isInitialized()) {
        throw new TaskomaticException("HibernateFactory failed to initialize");
    }
    MessageQueue.startMessaging();
    MessageQueue.configureDefaultActions(SYSTEM_QUERY, SaltService.INSTANCE_SALT_API);
    try {
        SchedulerKernel.scheduler.start();
        initializeAllSatSchedules();
        synchronized (this.shutdownLock) {
            try {
                this.shutdownLock.wait();
            }
            catch (InterruptedException ignored) {
                return;
            }
        }
    }
    catch (SchedulerException e) {
        throw new TaskomaticException(e.getMessage(), e);
    }
}
 
Example 6
Source File: JobScheduleController.java    From DataLink with Apache License 2.0 5 votes vote down vote up
@ResponseBody
@RequestMapping(value = "/startSchedule")
public String startSchedule(HttpServletRequest request) {
    try {
        QuartzManager.getInstance().startSchedule();
    } catch (SchedulerException e) {
        logger.error(e.getMessage(),e);
        return e.getMessage();
    }
    return "success";
}
 
Example 7
Source File: SfbestSchedulerContainer.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * 启动QuartzScheduler
 *
 * @author zhangshaobin
 * @created 2013-1-4 下午4:11:50
 *
 */
public void start() throws BusinessException {
	try {
		SchedulerFactory sf = new StdSchedulerFactory("quartz.properties");
		scheduler = sf.getScheduler();
		scheduler.start();
		logger.info(new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss]").format(new Date()) + " Quartz started!");
	} catch (SchedulerException e) {
		logger.error("启动Quartz出错:" + e.getMessage(), e.getCause());
		throw new BusinessException(e.getMessage(), e.getCause());
	}
}
 
Example 8
Source File: SfbestSchedulerContainer.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * 停止QuartzScheduler
 *
 * @author zhangshaobin
 * @created 2013-1-4 下午5:18:15
 *
 * @throws BusinessException
 */
public void stop() throws BusinessException {
	if (null != scheduler) {
		try {
			scheduler.shutdown();
		} catch (SchedulerException e) {
			logger.error("停止Quartz出错:" + e.getMessage(), e.getCause());
			throw new BusinessException(e.getMessage(), e.getCause());
		}
	}
}
 
Example 9
Source File: JobScheduleController.java    From DataLink with Apache License 2.0 5 votes vote down vote up
@ResponseBody
@RequestMapping(value = "/stopSchedule")
public String stopSchedule(HttpServletRequest request) {
    try {
        QuartzManager.getInstance().stopSchedule();
    } catch (SchedulerException e) {
        logger.error(e.getMessage(),e);
        return e.getMessage();
    }
    return "success";
}
 
Example 10
Source File: ScheduleServiceImpl.java    From fixflow with Apache License 2.0 5 votes vote down vote up
public void schedulerStart() {
	if(!getIsEnabled()){
		throw new FixFlowScheduleException(ExceptionCode.QUARZTEXCEPTION_ISENABLE);
	}
	Scheduler scheduler;
	try {
		scheduler = getScheduler();
		if(scheduler.isInStandbyMode()){
			scheduler.start();
		}
	} catch (SchedulerException e) {
		throw new FixFlowException(e.getMessage(),e);
	}
}
 
Example 11
Source File: ScheduleServiceImpl.java    From fixflow with Apache License 2.0 5 votes vote down vote up
public void schedulerShutdown() {
	if(!getIsEnabled()){
		throw new FixFlowScheduleException(ExceptionCode.QUARZTEXCEPTION_ISENABLE);
	}
	Scheduler scheduler;
	try {
		scheduler = getScheduler();
		if(!scheduler.isInStandbyMode()){
			scheduler.standby();
		}
	} catch (SchedulerException e) {
		throw new FixFlowException(e.getMessage(),e);
	}
}
 
Example 12
Source File: ScheduleServiceImpl.java    From fixflow with Apache License 2.0 5 votes vote down vote up
public void suspendJob(String name, String group) {
	if(!getIsEnabled()){
		throw new FixFlowScheduleException(ExceptionCode.QUARZTEXCEPTION_ISENABLE);
	}
	Scheduler scheduler = getScheduler();
	try {
		scheduler.pauseJob(new JobKey(name,group));
	} catch (SchedulerException e) {
		throw new FixFlowException(e.getMessage(),e);
	}
}
 
Example 13
Source File: ScheduleServiceImpl.java    From fixflow with Apache License 2.0 5 votes vote down vote up
public void continueJob(String name, String group) {
	if(!getIsEnabled()){
		throw new FixFlowScheduleException(ExceptionCode.QUARZTEXCEPTION_ISENABLE);
	}
	Scheduler scheduler = getScheduler();
	try {
		scheduler.resumeJob(new JobKey(name,group));
	} catch (SchedulerException e) {
		throw new FixFlowException(e.getMessage(),e);
	}
}
 
Example 14
Source File: ScheduleServiceImpl.java    From fixflow with Apache License 2.0 5 votes vote down vote up
public void suspendTrigger(String triggerName, String triggerGroup) {
	if(!getIsEnabled()){
		throw new FixFlowScheduleException(ExceptionCode.QUARZTEXCEPTION_ISENABLE);
	}
	Scheduler scheduler = getScheduler();
	TriggerKey tKey = new TriggerKey(triggerName,triggerGroup);
	try {
		scheduler.pauseTrigger(tKey);
	} catch (SchedulerException e) {
		throw new FixFlowException(e.getMessage(),e);
	}
}
 
Example 15
Source File: ScheduleServiceImpl.java    From fixflow with Apache License 2.0 5 votes vote down vote up
public void continueTrigger(String triggerName, String triggerGroup) {
	if(!getIsEnabled()){
		throw new FixFlowScheduleException(ExceptionCode.QUARZTEXCEPTION_ISENABLE);
	}
	Scheduler scheduler = getScheduler();
	TriggerKey tKey = new TriggerKey(triggerName,triggerGroup);
	try {
		scheduler.resumeTrigger(tKey);
	} catch (SchedulerException e) {
		throw new FixFlowException(e.getMessage(),e);
	}
}
 
Example 16
Source File: XxlJobServiceImpl.java    From xmfcn-spring-cloud 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>(ResultCodeMessage.FAILURE, (I18nUtil.getString("system_please_choose") + I18nUtil.getString("jobinfo_field_jobgroup")));
    }
    if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
        return new ReturnT<String>(ResultCodeMessage.FAILURE, I18nUtil.getString("jobinfo_field_cron_unvalid"));
    }
    if (StringUtils.isBlank(jobInfo.getJobDesc())) {
        return new ReturnT<String>(ResultCodeMessage.FAILURE, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_field_jobdesc")));
    }
    if (StringUtils.isBlank(jobInfo.getAuthor())) {
        return new ReturnT<String>(ResultCodeMessage.FAILURE, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_field_author")));
    }
    if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
        return new ReturnT<String>(ResultCodeMessage.FAILURE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy") + I18nUtil.getString("system_unvalid")));
    }
    if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
        return new ReturnT<String>(ResultCodeMessage.FAILURE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy") + I18nUtil.getString("system_unvalid")));
    }
    if (GlueTypeEnum.match(jobInfo.getGlueType()) == null) {
        return new ReturnT<String>(ResultCodeMessage.FAILURE, (I18nUtil.getString("jobinfo_field_gluetype") + I18nUtil.getString("system_unvalid")));
    }
    if (GlueTypeEnum.BEAN == GlueTypeEnum.match(jobInfo.getGlueType()) && StringUtils.isBlank(jobInfo.getExecutorHandler())) {
        return new ReturnT<String>(ResultCodeMessage.FAILURE, (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>(ResultCodeMessage.FAILURE,
                            MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId") + "({0})" + I18nUtil.getString("system_not_found")), childJobIdItem));
                }
            } else {
                return new ReturnT<String>(ResultCodeMessage.FAILURE,
                        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>(ResultCodeMessage.FAILURE, (I18nUtil.getString("jobinfo_field_add") + I18nUtil.getString("system_fail")));
    }

    // add in quartz
    String qzGroup = String.valueOf(jobInfo.getJobGroup());
    String qzName = String.valueOf(jobInfo.getId());
    try {
        XxlJobDynamicScheduler.addJob(qzName, qzGroup, jobInfo.getJobCron());
        clearCache();
        //XxlJobDynamicScheduler.pauseJob(qzName, qzGroup);
        return ReturnT.SUCCESS;
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        try {
            xxlJobInfoDao.delete(jobInfo.getId());
            XxlJobDynamicScheduler.removeJob(qzName, qzGroup);
        } catch (SchedulerException e1) {
            logger.error(e.getMessage(), e1);
        }
        return new ReturnT<String>(ResultCodeMessage.FAILURE, (I18nUtil.getString("jobinfo_field_add") + I18nUtil.getString("system_fail")) + ":" + e.getMessage());
    }
}
 
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());
       }
}