@Override public RemotingCommand processRequest(Channel channel, RemotingCommand request) throws RemotingCommandException { JobProtos.RequestCode code = JobProtos.RequestCode.valueOf(request.getCode()); RemotingProcessor processor = processors.get(code); if (processor == null) { return RemotingCommand.createResponseCommand(RemotingProtos.ResponseCode.REQUEST_CODE_NOT_SUPPORTED.code(), "request code not supported!"); } return processor.processRequest(channel, request); }
@Override public RemotingCommand processRequest(Channel channel, RemotingCommand request) throws RemotingCommandException { JobProtos.RequestCode code = valueOf(request.getCode()); RemotingProcessor processor = processors.get(code); if (processor == null) { return RemotingCommand.createResponseCommand(RemotingProtos.ResponseCode.REQUEST_CODE_NOT_SUPPORTED.code(), "request code not supported!"); } return processor.processRequest(channel, request); } }
@Override public RemotingCommand processRequest(Channel channel, RemotingCommand request) throws RemotingCommandException { JobProtos.RequestCode code = valueOf(request.getCode()); RemotingProcessor processor = processors.get(code); if (processor == null) { return RemotingCommand.createResponseCommand(RemotingProtos.ResponseCode.REQUEST_CODE_NOT_SUPPORTED.code(), "request code not supported!"); } return processor.processRequest(channel, request); } }
@Override public RemotingCommand processRequest(Channel channel, RemotingCommand request) throws RemotingCommandException { JobProtos.RequestCode code = JobProtos.RequestCode.valueOf(request.getCode()); RemotingProcessor processor = processors.get(code); if (processor == null) { return RemotingCommand.createResponseCommand(RemotingProtos.ResponseCode.REQUEST_CODE_NOT_SUPPORTED.code(), "request code not supported!"); } return processor.processRequest(channel, request); }
@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); } } } });
@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); } } } });
private RemotingCommand doBiz(Channel channel, RemotingCommand request) throws RemotingCommandException { // 其他的请求code RequestCode code = RequestCode.valueOf(request.getCode()); RemotingProcessor processor = processors.get(code); if (processor == null) { return RemotingCommand.createResponseCommand(RemotingProtos.ResponseCode.REQUEST_CODE_NOT_SUPPORTED.code(), "request code not supported!"); } offerHandler(channel, request); return processor.processRequest(channel, request); }
private RemotingCommand doBiz(Channel channel, RemotingCommand request) throws RemotingCommandException { // 其他的请求code RequestCode code = RequestCode.valueOf(request.getCode()); RemotingProcessor processor = processors.get(code); if (processor == null) { return RemotingCommand.createResponseCommand(RemotingProtos.ResponseCode.REQUEST_CODE_NOT_SUPPORTED.code(), "request code not supported!"); } offerHandler(channel, request); return processor.processRequest(channel, request); }
@Override public void operationComplete(ResponseFuture responseFuture) { try { RemotingCommand commandResponse = responseFuture.getResponseCommand(); if (commandResponse != null && commandResponse.getCode() == JobProtos.ResponseCode.JOB_NOTIFY_SUCCESS.code()) { clientNotifyHandler.handleSuccess(results); result.set(true); } else { result.set(false); } } finally { latch.countDown(); } } });
@Override public void operationComplete(ResponseFuture responseFuture) { try { RemotingCommand commandResponse = responseFuture.getResponseCommand(); if (commandResponse != null && commandResponse.getCode() == JobProtos.ResponseCode.JOB_NOTIFY_SUCCESS.code()) { clientNotifyHandler.handleSuccess(results); result.set(true); } else { result.set(false); } } finally { latch.countDown(); } } });
@Override public RemotingCommand processRequest(Channel channel, RemotingCommand request) throws RemotingCommandException { // 心跳 if (request.getCode() == JobProtos.RequestCode.HEART_BEAT.code()) { offerHandler(channel, request); return RemotingCommand.createResponseCommand(JobProtos.ResponseCode.HEART_BEAT_SUCCESS.code(), ""); } if (reqLimitEnable) { return doBizWithReqLimit(channel, request); } else { return doBiz(channel, request); } }
@Override public RemotingCommand processRequest(Channel channel, RemotingCommand request) throws RemotingCommandException { // 心跳 if (request.getCode() == JobProtos.RequestCode.HEART_BEAT.code()) { offerHandler(channel, request); return RemotingCommand.createResponseCommand(JobProtos.ResponseCode.HEART_BEAT_SUCCESS.code(), ""); } if (reqLimitEnable) { return doBizWithReqLimit(channel, request); } else { return doBiz(channel, request); } }
@Override public void operationComplete(ResponseFuture responseFuture) { RemotingCommand response = responseFuture.getResponseCommand(); if (response != null && RemotingProtos.ResponseCode.SUCCESS.code() == response.getCode()) { JobAskResponse responseBody = response.getBody(); List<String> deadJobIds = responseBody.getJobIds(); if (CollectionUtils.isNotEmpty(deadJobIds)) { // 睡了1秒再修复, 防止任务刚好执行完正在传输中. 1s可以让完成的正常完成 QuietUtils.sleep(appContext.getConfig().getParameter(ExtConfig.JOB_TRACKER_FIX_EXECUTING_JOB_WAITING_MILLS, 1000L)); for (JobPo jobPo : jobPos) { if (deadJobIds.contains(jobPo.getJobId())) { fixDeadJob(jobPo); } } } } } });
@Override public void operationComplete(ResponseFuture responseFuture) { RemotingCommand response = responseFuture.getResponseCommand(); if (response != null && RemotingProtos.ResponseCode.SUCCESS.code() == response.getCode()) { JobAskResponse responseBody = response.getBody(); List<String> deadJobIds = responseBody.getJobIds(); if (CollectionUtils.isNotEmpty(deadJobIds)) { // 睡了1秒再修复, 防止任务刚好执行完正在传输中. 1s可以让完成的正常完成 QuietUtils.sleep(appContext.getConfig().getParameter(ExtConfig.JOB_TRACKER_FIX_EXECUTING_JOB_WAITING_MILLS, 1000L)); for (JobPo jobPo : jobPos) { if (deadJobIds.contains(jobPo.getJobId())) { fixDeadJob(jobPo); } } } } } });
private boolean sendBizLog(List<BizLog> bizLogs) { if (CollectionUtils.isEmpty(bizLogs)) { return true; } BizLogSendRequest requestBody = CommandBodyWrapper.wrapper(appContext, new BizLogSendRequest()); requestBody.setBizLogs(bizLogs); RemotingCommand request = RemotingCommand.createRequestCommand(JobProtos.RequestCode.BIZ_LOG_SEND.code(), requestBody); try { RemotingCommand response = remotingClient.invokeSync(request); if (response != null && response.getCode() == JobProtos.ResponseCode.BIZ_LOG_SEND_SUCCESS.code()) { // success return true; } } catch (JobTrackerNotFoundException ignored) { } return false; }
/** * 发送心跳 */ private boolean beat(RemotingClientDelegate remotingClient, String addr) { HeartBeatRequest commandBody = appContext.getCommandBodyWrapper().wrapper(new HeartBeatRequest()); RemotingCommand request = RemotingCommand.createRequestCommand( JobProtos.RequestCode.HEART_BEAT.code(), commandBody); try { RemotingCommand response = remotingClient.getRemotingClient().invokeSync(addr, request, 5000); if (response != null && JobProtos.ResponseCode.HEART_BEAT_SUCCESS == JobProtos.ResponseCode.valueOf(response.getCode())) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("heart beat success. "); } return true; } } catch (Exception e) { LOGGER.warn(e.getMessage()); } return false; }
private boolean sendBizLog(List<BizLog> bizLogs) { if (CollectionUtils.isEmpty(bizLogs)) { return true; } BizLogSendRequest requestBody = CommandBodyWrapper.wrapper(appContext, new BizLogSendRequest()); requestBody.setBizLogs(bizLogs); RemotingCommand request = RemotingCommand.createRequestCommand(JobProtos.RequestCode.BIZ_LOG_SEND.code(), requestBody); try { RemotingCommand response = remotingClient.invokeSync(request); if (response != null && response.getCode() == JobProtos.ResponseCode.BIZ_LOG_SEND_SUCCESS.code()) { // success return true; } } catch (JobTrackerNotFoundException ignored) { } return false; }
/** * 发送心跳 */ private boolean beat(RemotingClientDelegate remotingClient, String addr) { HeartBeatRequest commandBody = appContext.getCommandBodyWrapper().wrapper(new HeartBeatRequest()); RemotingCommand request = RemotingCommand.createRequestCommand( JobProtos.RequestCode.HEART_BEAT.code(), commandBody); try { RemotingCommand response = remotingClient.getRemotingClient().invokeSync(addr, request, 5000); if (response != null && JobProtos.ResponseCode.HEART_BEAT_SUCCESS == JobProtos.ResponseCode.valueOf(response.getCode())) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("heart beat success. "); } return true; } } catch (Exception e) { LOGGER.warn(e.getMessage()); } return false; }
@Override public void call(RemotingCommand responseCommand) { if (responseCommand == null) { response.setFailedJobs(jobs); response.setSuccess(false); response.setMsg("Submit Job failed: JobTracker is broken"); LOGGER.warn("Submit Job failed: {}, {}", jobs, "JobTracker is broken"); return; } if (JobProtos.ResponseCode.JOB_RECEIVE_SUCCESS.code() == responseCommand.getCode()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Submit Job success: {}", jobs); } response.setSuccess(true); return; } // 失败的job JobSubmitResponse jobSubmitResponse = responseCommand.getBody(); response.setFailedJobs(jobSubmitResponse.getFailedJobs()); response.setSuccess(false); response.setCode(JobProtos.ResponseCode.valueOf(responseCommand.getCode()).name()); response.setMsg("Submit Job failed: " + responseCommand.getRemark() + " " + jobSubmitResponse.getMsg()); LOGGER.warn("Submit Job failed: {}, {}, {}", jobs, responseCommand.getRemark(), jobSubmitResponse.getMsg()); } };
/** * 发送JobResults */ private boolean retrySendJobResults(List<JobRunResult> results) { // 发送消息给 JobTracker JobCompletedRequest requestBody = appContext.getCommandBodyWrapper().wrapper(new JobCompletedRequest()); requestBody.setJobRunResults(results); requestBody.setReSend(true); int requestCode = JobProtos.RequestCode.JOB_COMPLETED.code(); RemotingCommand request = RemotingCommand.createRequestCommand(requestCode, requestBody); try { // 这里一定要用同步,不然异步会发生文件锁,死锁 RemotingCommand commandResponse = remotingClient.invokeSync(request); if (commandResponse != null && commandResponse.getCode() == RemotingProtos.ResponseCode.SUCCESS.code()) { return true; } else { LOGGER.warn("Send job failed, {}", commandResponse); return false; } } catch (JobTrackerNotFoundException e) { LOGGER.error("Retry send job result failed! jobResults={}", results, e); } return false; }