@Override public void call() throws Exception { retryScheduler.stop(); } });
@Override protected void beforeStart() { super.beforeStart(); jobRetryScheduler = new RetryScheduler<Job>(RetryJobClient.class.getSimpleName(), appContext, FailStorePathBuilder.getJobSubmitFailStorePath(appContext), 10) { protected boolean isRemotingEnable() { return isServerEnable(); } protected boolean retry(List<Job> jobs) { Response response = null; try { // 重试必须走同步,不然会造成文件锁,死锁 response = superSubmitJob(jobs, SubmitType.SYNC); return response.isSuccess(); } catch (Throwable t) { RetryScheduler.LOGGER.error(t.getMessage(), t); } finally { if (response != null && response.isSuccess()) { stat.incSubmitFailStoreNum(jobs.size()); } } return false; } }; jobRetryScheduler.start(); }
@Override public void operationComplete(ResponseFuture responseFuture) { RemotingCommand response = responseFuture.getResponseCommand(); if (response != null && response.getCode() == JobProtos.ResponseCode.BIZ_LOG_SEND_SUCCESS.code()) { // success } else { if (!isEnableBizLoggerFailStore()) { logger.error("Send Biz Logger to JobTracker Error, code={}, bizLog={}", response != null ? response.getCode() : null, JSON.toJSONString(bizLog)); } else { retryScheduler.inSchedule(StringUtils.generateUUID(), bizLog); } } } });
public void stop() { try { if (selfCheckStart.compareAndSet(true, false)) { if (scheduledFuture != null) { scheduledFuture.cancel(true); scheduledFuture = null; failStore.close(); RETRY_EXECUTOR_SERVICE.shutdown(); RETRY_EXECUTOR_SERVICE = null; } LOGGER.info("Stop {} RetryScheduler success, identity=[{}]", name, appContext.getConfig().getIdentity()); } stopMasterCheck(); } catch (Throwable t) { LOGGER.error("Stop {} RetryScheduler failed, identity=[{}]", name, appContext.getConfig().getIdentity(), t); } }
public RetryScheduler(String name, final AppContext appContext, String storePath) { this.name = name; this.appContext = appContext; FailStoreFactory failStoreFactory = ServiceLoader.load(FailStoreFactory.class, appContext.getConfig()); failStore = failStoreFactory.getFailStore(appContext.getConfig(), storePath); try { failStore.open(); } catch (FailStoreException e) { throw new RuntimeException(e); } EventSubscriber subscriber = new EventSubscriber(RetryScheduler.class.getSimpleName() .concat(appContext.getConfig().getIdentity()), new Observer() { @Override public void onObserved(EventInfo eventInfo) { Node masterNode = (Node) eventInfo.getParam("master"); if (masterNode != null && masterNode.getIdentity().equals(appContext.getConfig().getIdentity())) { startMasterCheck(); } else { stopMasterCheck(); } } }); appContext.getEventCenter().subscribe(subscriber, EcTopic.MASTER_CHANGED); if (appContext.getMasterElector().isCurrentMaster()) { startMasterCheck(); } }
@Override public void operationComplete(ResponseFuture responseFuture) { RemotingCommand response = responseFuture.getResponseCommand(); if (response != null && response.getCode() == JobProtos.ResponseCode.BIZ_LOG_SEND_SUCCESS.code()) { // success } else { if (!isEnableBizLoggerFailStore()) { logger.error("Send Biz Logger to JobTracker Error, code={}, bizLog={}", response != null ? response.getCode() : null, JSON.toJSONString(bizLog)); } else { retryScheduler.inSchedule(StringUtils.generateUUID(), bizLog); } } } });
public void stop() { try { if (selfCheckStart.compareAndSet(true, false)) { if (scheduledFuture != null) { scheduledFuture.cancel(true); scheduledFuture = null; failStore.close(); RETRY_EXECUTOR_SERVICE.shutdown(); RETRY_EXECUTOR_SERVICE = null; } LOGGER.info("Stop {} RetryScheduler success, identity=[{}]", name, appContext.getConfig().getIdentity()); } stopMasterCheck(); } catch (Throwable t) { LOGGER.error("Stop {} RetryScheduler failed, identity=[{}]", name, appContext.getConfig().getIdentity(), t); } }
public RetryScheduler(String name, final AppContext appContext, String storePath) { this.name = name; this.appContext = appContext; FailStoreFactory failStoreFactory = ServiceLoader.load(FailStoreFactory.class, appContext.getConfig()); failStore = failStoreFactory.getFailStore(appContext.getConfig(), storePath); try { failStore.open(); } catch (FailStoreException e) { throw new RuntimeException(e); } EventSubscriber subscriber = new EventSubscriber(RetryScheduler.class.getSimpleName() .concat(appContext.getConfig().getIdentity()), new Observer() { @Override public void onObserved(EventInfo eventInfo) { Node masterNode = (Node) eventInfo.getParam("master"); if (masterNode != null && masterNode.getIdentity().equals(appContext.getConfig().getIdentity())) { startMasterCheck(); } else { stopMasterCheck(); } } }); appContext.getEventCenter().subscribe(subscriber, EcTopic.MASTER_CHANGED); if (appContext.getMasterElector().isCurrentMaster()) { startMasterCheck(); } }
@Override public void call() throws Exception { retryScheduler.stop(); } });
retryScheduler.inSchedule( jobRunResult.getJobMeta().getJobId().concat("_") + SystemClock.now(), jobRunResult);
@Override protected void beforeStart() { super.beforeStart(); jobRetryScheduler = new RetryScheduler<Job>(RetryJobClient.class.getSimpleName(), appContext, FailStorePathBuilder.getJobSubmitFailStorePath(appContext), 10) { protected boolean isRemotingEnable() { return isServerEnable(); } protected boolean retry(List<Job> jobs) { Response response = null; try { // 重试必须走同步,不然会造成文件锁,死锁 response = superSubmitJob(jobs, SubmitType.SYNC); return response.isSuccess(); } catch (Throwable t) { RetryScheduler.LOGGER.error(t.getMessage(), t); } finally { if (response != null && response.isSuccess()) { stat.incSubmitFailStoreNum(jobs.size()); } } return false; } }; jobRetryScheduler.start(); }
public void stop() { try { if (selfCheckStart.compareAndSet(true, false)) { if (scheduledFuture != null) { scheduledFuture.cancel(true); scheduledFuture = null; failStore.close(); RETRY_EXECUTOR_SERVICE.shutdown(); RETRY_EXECUTOR_SERVICE = null; } LOGGER.info("Stop {} RetryScheduler success, identity=[{}]", name, appContext.getConfig().getIdentity()); } stopMasterCheck(); } catch (Throwable t) { LOGGER.error("Stop {} RetryScheduler failed, identity=[{}]", name, appContext.getConfig().getIdentity(), t); } }
public RetryScheduler(String name, final AppContext appContext, String storePath) { this.name = name; this.appContext = appContext; FailStoreFactory failStoreFactory = ServiceLoader.load(FailStoreFactory.class, appContext.getConfig()); failStore = failStoreFactory.getFailStore(appContext.getConfig(), storePath); try { failStore.open(); } catch (FailStoreException e) { throw new RuntimeException(e); } EventSubscriber subscriber = new EventSubscriber(RetryScheduler.class.getSimpleName() .concat(appContext.getConfig().getIdentity()), new Observer() { @Override public void onObserved(EventInfo eventInfo) { Node masterNode = (Node) eventInfo.getParam("master"); if (masterNode != null && masterNode.getIdentity().equals(appContext.getConfig().getIdentity())) { startMasterCheck(); } else { stopMasterCheck(); } } }); appContext.getEventCenter().subscribe(subscriber, EcTopic.MASTER_CHANGED); if (appContext.getMasterElector().isCurrentMaster()) { startMasterCheck(); } }
@Override public void call() throws Exception { retryScheduler.stop(); } });
retryScheduler.inSchedule( jobRunResult.getJobMeta().getJobId().concat("_") + SystemClock.now(), jobRunResult);
public BizLoggerImpl(Level level, final RemotingClientDelegate remotingClient, TaskTrackerAppContext appContext) { this.level = level; if (this.level == null) { this.level = Level.INFO; } this.appContext = appContext; this.remotingClient = remotingClient; if (isEnableBizLoggerFailStore()) { this.retryScheduler = new RetryScheduler<BizLog>(BizLogger.class.getSimpleName(), appContext, FailStorePathBuilder.getBizLoggerPath(appContext)) { @Override protected boolean isRemotingEnable() { return remotingClient.isServerEnable(); } @Override protected boolean retry(List<BizLog> list) { return sendBizLog(list); } }; this.retryScheduler.start(); NodeShutdownHook.registerHook(appContext, this.getClass().getName(), new Callable() { @Override public void call() throws Exception { retryScheduler.stop(); } }); } }
@Override public void call() throws Exception { retryScheduler.stop(); } });
@Override public Response submitJob(List<Job> jobs) { Response response; try { response = superSubmitJob(jobs); } catch (JobSubmitProtectException e) { response = new Response(); response.setSuccess(false); response.setFailedJobs(jobs); response.setCode(ResponseCode.SUBMIT_TOO_BUSY_AND_SAVE_FOR_LATER); response.setMsg(response.getMsg() + ", submit too busy"); } if (!response.isSuccess()) { try { for (Job job : response.getFailedJobs()) { jobRetryScheduler.inSchedule(job.getTaskId(), job); stat.incFailStoreNum(); } response.setSuccess(true); response.setCode(ResponseCode.SUBMIT_FAILED_AND_SAVE_FOR_LATER); response.setMsg(response.getMsg() + ", save local fail store and send later !"); LOGGER.warn(JSON.toJSONString(response)); } catch (Exception e) { response.setSuccess(false); response.setMsg(e.getMessage()); } } return response; }
public BizLoggerImpl(Level level, final RemotingClientDelegate remotingClient, TaskTrackerAppContext appContext) { this.level = level; if (this.level == null) { this.level = Level.INFO; } this.appContext = appContext; this.remotingClient = remotingClient; if (isEnableBizLoggerFailStore()) { this.retryScheduler = new RetryScheduler<BizLog>(BizLogger.class.getSimpleName(), appContext, FailStorePathBuilder.getBizLoggerPath(appContext)) { @Override protected boolean isRemotingEnable() { return remotingClient.isServerEnable(); } @Override protected boolean retry(List<BizLog> list) { return sendBizLog(list); } }; this.retryScheduler.start(); NodeShutdownHook.registerHook(appContext, this.getClass().getName(), new Callable() { @Override public void call() throws Exception { retryScheduler.stop(); } }); } }
@Override protected void beforeStop() { super.beforeStop(); jobRetryScheduler.stop(); }