public void healthCheckerTest(String script, HealthCheckerExitStatus expectedStatus) throws Exception { Configuration config = getConfForNodeHealthScript(); config.addResource(healthScriptFile.getName()); String location = healthScriptFile.getAbsolutePath(); long timeout = config.getLong(HConstants.HEALTH_SCRIPT_TIMEOUT, SCRIPT_TIMEOUT); HealthChecker checker = new HealthChecker(); checker.init(location, timeout); createScript(script, true); HealthReport report = checker.checkHealth(); assertEquals(expectedStatus, report.getStatus()); LOG.info("Health Status:" + report.getHealthReport()); this.healthScriptFile.delete(); }
public void healthCheckerTest(String script, HealthCheckerExitStatus expectedStatus) throws Exception { Configuration config = getConfForNodeHealthScript(); config.addResource(healthScriptFile.getName()); String location = healthScriptFile.getAbsolutePath(); long timeout = config.getLong(HConstants.HEALTH_SCRIPT_TIMEOUT, 2000); HealthChecker checker = new HealthChecker(); checker.init(location, timeout); createScript(script, true); HealthReport report = checker.checkHealth(); assertEquals(expectedStatus, report.getStatus()); LOG.info("Health Status:" + report.getHealthReport()); this.healthScriptFile.delete(); }
@Override protected void chore() { HealthReport report = healthChecker.checkHealth(); boolean isHealthy = (report.getStatus() == HealthCheckerExitStatus.SUCCESS); if (!isHealthy) { boolean needToStop = decideToStop(); if (needToStop) { getStopper().stop( "The node reported unhealthy " + threshold + " number of times consecutively."); } // Always log health report. LOG.info("Health status at " + StringUtils.formatTime(System.currentTimeMillis()) + " : " + report.getHealthReport()); } }
@Override protected void chore() { HealthReport report = healthChecker.checkHealth(); boolean isHealthy = (report.getStatus() == HealthCheckerExitStatus.SUCCESS); if (!isHealthy) { boolean needToStop = decideToStop(); if (needToStop) { this.stopper.stop("The region server reported unhealthy " + threshold + " number of times consecutively."); } // Always log health report. LOG.info("Health status at " + StringUtils.formatTime(System.currentTimeMillis()) + " : " + report.getHealthReport()); } }
@Test public void testHealthChecker() throws Exception { Configuration config = getConfForNodeHealthScript(); config.addResource(healthScriptFile.getName()); String location = healthScriptFile.getAbsolutePath(); long timeout = config.getLong(HConstants.HEALTH_SCRIPT_TIMEOUT, 200); HealthChecker checker = new HealthChecker(); checker.init(location, timeout); String normalScript = "echo \"I am all fine\""; createScript(normalScript, true); HealthReport report = checker.checkHealth(); assertEquals(HealthCheckerExitStatus.SUCCESS, report.getStatus()); LOG.info("Health Status:" + checker); String errorScript = "echo ERROR\n echo \"Node not healthy\""; createScript(errorScript, true); report = checker.checkHealth(); assertEquals(HealthCheckerExitStatus.FAILED, report.getStatus()); LOG.info("Health Status:" + report.getHealthReport()); String timeOutScript = "sleep 4\n echo\"I am fine\""; createScript(timeOutScript, true); report = checker.checkHealth(); assertEquals(HealthCheckerExitStatus.TIMED_OUT, report.getStatus()); LOG.info("Health Status:" + report.getHealthReport()); healthScriptFile.delete(); }
@Override protected void chore() { HealthReport report = healthChecker.checkHealth(); boolean isHealthy = (report.getStatus() == HealthCheckerExitStatus.SUCCESS); if (!isHealthy) { boolean needToStop = decideToStop(); if (needToStop) { this.stopper.stop("The node reported unhealthy " + threshold + " number of times consecutively."); } // Always log health report. LOG.info("Health status at " + StringUtils.formatTime(System.currentTimeMillis()) + " : " + report.getHealthReport()); } }
@Override protected void chore() { HealthReport report = healthChecker.checkHealth(); boolean isHealthy = (report.getStatus() == HealthCheckerExitStatus.SUCCESS); if (!isHealthy) { boolean needToStop = decideToStop(); if (needToStop) { this.getStopper().stop("The node reported unhealthy " + threshold + " number of times consecutively."); } // Always log health report. LOG.info("Health status at " + StringUtils.formatTime(System.currentTimeMillis()) + " : " + report.getHealthReport()); } }
@Test public void testHealthChecker() throws Exception { Configuration config = getConfForNodeHealthScript(); config.addResource(healthScriptFile.getName()); String location = healthScriptFile.getAbsolutePath(); long timeout = config.getLong(HConstants.HEALTH_SCRIPT_TIMEOUT, 100); String normalScript = "echo \"I am all fine\""; createScript(normalScript, true); HealthChecker checker = new HealthChecker(); checker.init(location, timeout); HealthReport report = checker.checkHealth(); assertTrue(report.getStatus() == HealthCheckerExitStatus.SUCCESS); LOG.info("Health Status:" + checker); String errorScript = "echo ERROR\n echo \"Server not healthy\""; createScript(errorScript, true); report = checker.checkHealth(); assertTrue(report.getStatus() == HealthCheckerExitStatus.FAILED); LOG.info("Health Status:" + report.getHealthReport()); String timeOutScript = "sleep 4\n echo\"I am fine\""; createScript(timeOutScript, true); report = checker.checkHealth(); assertTrue(report.getStatus() == HealthCheckerExitStatus.TIMED_OUT); LOG.info("Health Status:" + report.getHealthReport()); healthScriptFile.delete(); }
HealthReport(HealthCheckerExitStatus status, String healthReport) { super(); this.status = status; this.healthReport = healthReport; }
@Test(timeout=60000) public void testHealthCheckerSuccess() throws Exception { String normalScript = "echo \"I am all fine\""; healthCheckerTest(normalScript, HealthCheckerExitStatus.SUCCESS); }
@Test(timeout=60000) public void testHealthCheckerFail() throws Exception { String errorScript = "echo ERROR" + eol + "echo \"Node not healthy\""; healthCheckerTest(errorScript, HealthCheckerExitStatus.FAILED); }
@Test(timeout=60000) public void testHealthCheckerTimeout() throws Exception { String timeOutScript = "sleep 10" + eol + "echo \"I am fine\""; healthCheckerTest(timeOutScript, HealthCheckerExitStatus.TIMED_OUT); }