com.xxl.job.core.biz.model.ReturnT Java Examples

The following examples show how to use com.xxl.job.core.biz.model.ReturnT. 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: AdminBizTest.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
/**
 * registry executor
 *
 * @throws Exception
 */
@Test
public void registryTest() throws Exception {
    addressUrl = addressUrl.replace("http://", "");
    AdminBiz adminBiz = (AdminBiz) new XxlRpcReferenceBean(
            NetEnum.JETTY,
            Serializer.SerializeEnum.HESSIAN.getSerializer(),
            CallType.SYNC,
            LoadBalance.ROUND,
            AdminBiz.class,
            null,
            10000,
            addressUrl,
            accessToken,
            null,
            null).getObject();

    // test executor registry
    RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
    ReturnT<String> returnT = adminBiz.registry(registryParam);
    Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);

    // stop invoker
    XxlRpcInvokerFactory.getInstance().stop();
}
 
Example #2
Source File: ScheduleService.java    From frostmourne with MIT License 6 votes vote down vote up
@Override
public Integer addJob(Long alarmId, String cron, String status) {
    XxlJobInfo xxlJobInfo = toXxlJobInfo(alarmId, cron, new Date());
    xxlJobInfo.setAddTime(xxlJobInfo.getUpdateTime());
    ReturnT<String> returnT = xxlJobApi.addJob(xxlJobInfo);
    if (returnT.getCode() != 200) {
        throw new RuntimeException("error when addJob, return: " + JacksonUtil.serialize(returnT));
    }
    Integer jobId = Integer.parseInt(returnT.getContent());
    if (status.equalsIgnoreCase(AlarmStatus.OPEN)) {
        try {
            this.openJob(jobId);
        } catch (Exception ex) {
            this.removeJob(jobId);
            throw ex;
        }
    }
    return jobId;
}
 
Example #3
Source File: ShardingJobHandler.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {

	// 分片参数
	ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
	XxlJobLogger.log("分片参数:当前分片序号 = {0}, 总分片数 = {1}", shardingVO.getIndex(), shardingVO.getTotal());

	// 业务逻辑
	for (int i = 0; i < shardingVO.getTotal(); i++) {
		if (i == shardingVO.getIndex()) {
			XxlJobLogger.log("第 {0} 片, 命中分片开始处理", i);
		} else {
			XxlJobLogger.log("第 {0} 片, 忽略", i);
		}
	}

	return SUCCESS;
}
 
Example #4
Source File: JobLogController.java    From xxl-job with GNU General Public License v3.0 6 votes vote down vote up
@RequestMapping("/logDetailPage")
public String logDetailPage(int id, Model model){

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

       model.addAttribute("triggerCode", jobLog.getTriggerCode());
       model.addAttribute("handleCode", jobLog.getHandleCode());
       model.addAttribute("executorAddress", jobLog.getExecutorAddress());
       model.addAttribute("triggerTime", jobLog.getTriggerTime().getTime());
       model.addAttribute("logId", jobLog.getId());
	return "joblog/joblog.detail";
}
 
Example #5
Source File: IndexController.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "login", method = RequestMethod.POST)
@ResponseBody
@PermessionLimit(limit = false)
public ReturnT<String> loginDo(HttpServletRequest request, HttpServletResponse response, String userName, String password, String ifRemember) {
    // valid
    if (PermissionInterceptor.ifLogin(request)) {
        return ReturnT.SUCCESS;
    }

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

    // do login
    boolean loginRet = PermissionInterceptor.login(response, userName, password, ifRem);
    if (!loginRet) {
        return new ReturnT<String>(500, I18nUtil.getString("login_param_unvalid"));
    }
    return ReturnT.SUCCESS;
}
 
Example #6
Source File: ShardingJobHandler.java    From xxl-job with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {

	// 分片参数
	int shardIndex = XxlJobContext.getXxlJobContext().getShardIndex();
	int shardTotal = XxlJobContext.getXxlJobContext().getShardTotal();

	XxlJobLogger.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardIndex, shardTotal);

	// 业务逻辑
	for (int i = 0; i < shardTotal; i++) {
		if (i == shardIndex) {
			XxlJobLogger.log("第 {} 片, 命中分片开始处理", i);
		} else {
			XxlJobLogger.log("第 {} 片, 忽略", i);
		}
	}

	return SUCCESS;
}
 
Example #7
Source File: SampleXxlJob.java    From xxl-job with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 2、分片广播任务
 */
@XxlJob("shardingJobHandler")
public ReturnT<String> shardingJobHandler(String param) throws Exception {

    // 分片参数
    int shardIndex = XxlJobContext.getXxlJobContext().getShardIndex();
    int shardTotal = XxlJobContext.getXxlJobContext().getShardTotal();

    XxlJobLogger.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardIndex, shardTotal);

    // 业务逻辑
    for (int i = 0; i < shardTotal; i++) {
        if (i == shardIndex) {
            XxlJobLogger.log("第 {} 片, 命中分片开始处理", i);
        } else {
            XxlJobLogger.log("第 {} 片, 忽略", i);
        }
    }

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

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

	// do login
	boolean loginRet = PermissionInterceptor.login(response, userName, password, ifRem);
	if (!loginRet) {
		return new ReturnT<String>(500, I18nUtil.getString("login_param_unvalid"));
	}
	return ReturnT.SUCCESS;
}
 
Example #10
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 #11
Source File: JobLogController.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/logDetailCat")
@ResponseBody
public ReturnT<LogResult> logDetailCat(String executorAddress, long triggerTime, Integer logId, Integer 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 #12
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 #13
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 #14
Source File: SampleXxlJob.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 1、简单任务示例(Bean模式)
 */
@XxlJob("demoJobHandler")
public ReturnT<String> demoJobHandler(String param) throws Exception {
    XxlJobLogger.log("XXL-JOB, Hello World.");

    for (int i = 0; i < 5; i++) {
        XxlJobLogger.log("beat at:" + i);
        TimeUnit.SECONDS.sleep(2);
    }
    return ReturnT.SUCCESS;
}
 
Example #15
Source File: ExecutorRouteBusyover.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #16
Source File: DemoJobHandler.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {
    XxlJobLogger.log("XXL-JOB, Hello World.");
    for (int i = 0; i < 5; i++) {
        XxlJobLogger.log("beat at:" + i);
        TimeUnit.SECONDS.sleep(2);
    }
    return SUCCESS;
}
 
Example #17
Source File: JobLogController.java    From xxl-job with GNU General Public License v3.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 = DateUtil.addMonths(new Date(), -1);	// 清理一个月之前日志数据
	} else if (type == 2) {
		clearBeforeTime = DateUtil.addMonths(new Date(), -3);	// 清理三个月之前日志数据
	} else if (type == 3) {
		clearBeforeTime = DateUtil.addMonths(new Date(), -6);	// 清理六个月之前日志数据
	} else if (type == 4) {
		clearBeforeTime = DateUtil.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"));
	}

	List<Long> logIds = null;
	do {
		logIds = xxlJobLogDao.findClearLogIds(jobGroup, jobId, clearBeforeTime, clearBeforeNum, 1000);
		if (logIds!=null && logIds.size()>0) {
			xxlJobLogDao.clearLog(logIds);
		}
	} while (logIds!=null && logIds.size()>0);

	return ReturnT.SUCCESS;
}
 
Example #18
Source File: ScheduleService.java    From frostmourne with MIT License 5 votes vote down vote up
@Override
public void removeJob(Integer jobId) {
    ReturnT<String> returnT = xxlJobApi.remove(jobId);
    if (returnT.getCode() != 200) {
        throw new RuntimeException("error when removeJob, return: " + JacksonUtil.serialize(returnT));
    }
}
 
Example #19
Source File: ExecutorRouteFirst.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {

    // address
    String address = route(triggerParam.getJobId(), addressList);

    // run executor
    ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
    runResult.setContent(address);
    return runResult;
}
 
Example #20
Source File: JobCodeController.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping("/save")
@ResponseBody
public ReturnT<String> save(Model model, int id, String glueSource, String glueRemark) {
	// valid
	if (glueRemark==null) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_glue_remark")) );
	}
	if (glueRemark.length()<4 || glueRemark.length()>100) {
		return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_remark_limit"));
	}
	XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(id);
	if (exists_jobInfo == null) {
		return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
	}
	
	// update new code
	exists_jobInfo.setGlueSource(glueSource);
	exists_jobInfo.setGlueRemark(glueRemark);
	exists_jobInfo.setGlueUpdatetime(new Date());

	exists_jobInfo.setUpdateTime(new Date());
	xxlJobInfoDao.update(exists_jobInfo);

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

	xxlJobLogGlue.setAddTime(new Date());
	xxlJobLogGlue.setUpdateTime(new Date());
	xxlJobLogGlueDao.save(xxlJobLogGlue);

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

	return ReturnT.SUCCESS;
}
 
Example #21
Source File: JobCodeController.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/save")
@ResponseBody
public ReturnT<String> save(Model model, int id, String glueSource, String glueRemark) {
	// valid
	if (glueRemark==null) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_glue_remark")) );
	}
	if (glueRemark.length()<4 || glueRemark.length()>100) {
		return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_remark_limit"));
	}
	XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(id);
	if (exists_jobInfo == null) {
		return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
	}
	
	// update new code
	exists_jobInfo.setGlueSource(glueSource);
	exists_jobInfo.setGlueRemark(glueRemark);
	exists_jobInfo.setGlueUpdatetime(new Date());
	xxlJobInfoDao.update(exists_jobInfo);

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

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

	return ReturnT.SUCCESS;
}
 
Example #22
Source File: ExecutorRouteFailover.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 beatResultSB = new StringBuffer();
    for (String address : addressList) {
        // beat
        ReturnT<String> beatResult = null;
        try {
            ExecutorBiz executorBiz = XxlJobScheduler.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 #23
Source File: ExecutorBizImpl.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> idleBeat(int jobId) {

    // isRunningOrHasQueue
    boolean isRunningOrHasQueue = false;
    JobThread jobThread = XxlJobExecutor.loadJobThread(jobId);
    if (jobThread != null && jobThread.isRunningOrHasQueue()) {
        isRunningOrHasQueue = true;
    }

    if (isRunningOrHasQueue) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, "job thread is running or has trigger queue.");
    }
    return ReturnT.SUCCESS;
}
 
Example #24
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 #25
Source File: JobGroupController.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/save")
@ResponseBody
public ReturnT<String> save(XxlJobGroup xxlJobGroup) {

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

    int ret = xxlJobGroupDao.save(xxlJobGroup);
    return (ret > 0) ? ReturnT.SUCCESS : ReturnT.FAIL;
}
 
Example #26
Source File: JobCodeController.java    From zuihou-admin-boot 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 #27
Source File: JobFailMonitorHelper.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
/**
 * fail alarm
 *
 * @param jobLog
 */
private void failAlarm(XxlJobInfo info, XxlJobLog jobLog) {

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

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

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

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

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

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

}
 
Example #28
Source File: DemoJobHandler.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {
	XxlJobLogger.log("XXL-JOB, Hello World.");

	for (int i = 0; i < 5; i++) {
		XxlJobLogger.log("beat at:" + i);
		TimeUnit.SECONDS.sleep(2);
	}
	return SUCCESS;
}
 
Example #29
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 #30
Source File: AdminBizImpl.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> callback(List<HandleCallbackParam> callbackParamList) {
    for (HandleCallbackParam handleCallbackParam: callbackParamList) {
        ReturnT<String> callbackResult = callback(handleCallbackParam);
        logger.info(">>>>>>>>> JobApiController.callback {}, handleCallbackParam={}, callbackResult={}",
                (callbackResult.getCode()==IJobHandler.SUCCESS.getCode()?"success":"fail"), handleCallbackParam, callbackResult);
    }

    return ReturnT.SUCCESS;
}