@Override //AMRMClientAsync public void onError(Throwable e) { if (e instanceof InvalidResourceRequestException) { // stop the cluster LOG_YARN.error("AMRMClientAsync.onError() received {}", e, e); ActionStopSlider stopSlider = new ActionStopSlider("stop", EXIT_EXCEPTION_THROWN, FinalApplicationStatus.FAILED, SliderUtils.extractFirstLine(e.getLocalizedMessage())); stopSlider.setExitReason(SliderExitReason.APP_ERROR); signalAMComplete(stopSlider); } else if (e instanceof InvalidApplicationMasterRequestException) { // halt the AM LOG_YARN.error("AMRMClientAsync.onError() received {}", e, e); queue(new ActionHalt(EXIT_EXCEPTION_THROWN, SliderUtils.extractFirstLine(e.getLocalizedMessage()))); } else { // ignore and log LOG_YARN.info("Ignoring AMRMClientAsync.onError() received {}", e); } }
@Override //AMRMClientAsync public void onError(Throwable e) { if (e instanceof InvalidResourceRequestException) { // stop the cluster LOG_YARN.error("AMRMClientAsync.onError() received {}", e); ActionStopSlider stopSlider = new ActionStopSlider("stop", EXIT_EXCEPTION_THROWN, FinalApplicationStatus.FAILED, SliderUtils.extractFirstLine(e.getLocalizedMessage())); stopSlider.setExitReason(SliderExitReason.APP_ERROR); signalAMComplete(stopSlider); } else if (e instanceof InvalidApplicationMasterRequestException) { // halt the AM LOG_YARN.error("AMRMClientAsync.onError() received {}", e, e); queue(new ActionHalt(EXIT_EXCEPTION_THROWN, SliderUtils.extractFirstLine(e.getLocalizedMessage()))); } else { // ignore and log LOG_YARN.info("Ignoring AMRMClientAsync.onError() received {}", e); } }
/** * Handle any exception in a thread. If the exception provides an exit * code, that is the one that will be used. * @param thread thread throwing the exception * @param exception exception */ public void onExceptionInThread(Thread thread, Throwable exception) { log.error("Exception in {}: {}", thread.getName(), exception, exception); // if there is a teardown in progress, ignore it if (amCompletionFlag.get()) { log.info("Ignoring exception: shutdown in progress"); } else { int exitCode = EXIT_EXCEPTION_THROWN; if (exception instanceof ExitCodeProvider) { exitCode = ((ExitCodeProvider) exception).getExitCode(); } ActionStopSlider stopSlider = new ActionStopSlider("stop", exitCode, FinalApplicationStatus.FAILED, SliderUtils.extractFirstLine(exception.getLocalizedMessage())); stopSlider.setExitReason(SliderExitReason.SLIDER_AM_ERROR); signalAMComplete(stopSlider); } }
/** * Handle any exception in a thread. If the exception provides an exit * code, that is the one that will be used. * @param thread thread throwing the exception * @param exception exception */ public void onExceptionInThread(Thread thread, Throwable exception) { log.error("Exception in {}: {}", thread.getName(), exception, exception); // if there is a teardown in progress, ignore it if (amCompletionFlag.get()) { log.info("Ignoring exception: shutdown in progress"); } else { int exitCode = EXIT_EXCEPTION_THROWN; if (exception instanceof ExitCodeProvider) { exitCode = ((ExitCodeProvider) exception).getExitCode(); } ActionStopSlider stopSlider = new ActionStopSlider("stop", exitCode, FinalApplicationStatus.FAILED, SliderUtils.extractFirstLine(exception.getLocalizedMessage())); stopSlider.setExitReason(SliderExitReason.SLIDER_AM_ERROR); signalAMComplete(stopSlider); } }
@Test public void testExtractFirstLine() { String firstLine = "hello"; String msg = firstLine + "\n2nd line\n3rd line"; Assert.assertEquals("Should be first line only", firstLine, SliderUtils.extractFirstLine(msg)); msg = ""; Assert.assertEquals("Should be empty", msg, SliderUtils.extractFirstLine(msg)); msg = " "; Assert.assertEquals("Should contain spaces only", msg, SliderUtils.extractFirstLine(msg)); msg = null; Assert.assertEquals("Should be null", msg, SliderUtils.extractFirstLine(msg)); }
@Test public void testExtractFirstLine() { String firstLine = "hello"; String msg = firstLine + "\n2nd line\n3rd line"; Assert.assertEquals("Should be first line only", firstLine, SliderUtils.extractFirstLine(msg)); msg = ""; Assert.assertEquals("Should be empty", msg, SliderUtils.extractFirstLine(msg)); msg = " "; Assert.assertEquals("Should contain spaces only", msg, SliderUtils.extractFirstLine(msg)); msg = null; Assert.assertEquals("Should be null", msg, SliderUtils.extractFirstLine(msg)); } }