From 09151911679a608db31cca63c25cfd52818a311c Mon Sep 17 00:00:00 2001 From: Matteo Bertozzi Date: Fri, 20 Mar 2015 21:26:53 +0000 Subject: [PATCH] HBASE-13282 Fix the minor issues of running Canary on kerberized environment (Srikanth Srungarapu) --- .../org/apache/hadoop/hbase/AuthUtil.java | 6 +++--- .../org/apache/hadoop/hbase/tool/Canary.java | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/AuthUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/AuthUtil.java index f59793530fa..4754ea4c2f5 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/AuthUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/AuthUtil.java @@ -59,10 +59,10 @@ public class AuthUtil { conf.get("hbase.client.dns.nameserver", "default"))); userProvider.login("hbase.client.keytab.file", "hbase.client.kerberos.principal", host); } catch (UnknownHostException e) { - LOG.error("Error resolving host name"); + LOG.error("Error resolving host name: " + e.getMessage(), e); throw e; } catch (IOException e) { - LOG.error("Error while trying to perform the initial login"); + LOG.error("Error while trying to perform the initial login: " + e.getMessage(), e); throw e; } @@ -93,7 +93,7 @@ public class AuthUtil { try { ugi.checkTGTAndReloginFromKeytab(); } catch (IOException e) { - LOG.info("Got exception while trying to refresh credentials "); + LOG.error("Got exception while trying to refresh credentials: " + e.getMessage(), e); } } }; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/tool/Canary.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/tool/Canary.java index c8f0a724847..e5ad106b54f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/tool/Canary.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/tool/Canary.java @@ -338,6 +338,7 @@ public final class Canary implements Tool { @Override public int run(String[] args) throws Exception { int index = -1; + ChoreService choreService = null; // Process command line args for (int i = 0; i < args.length; i++) { @@ -411,6 +412,15 @@ public final class Canary implements Tool { } } + // Launches chore for refreshing kerberos credentials if security is enabled. + // Please see http://hbase.apache.org/book.html#_running_canary_in_a_kerberos_enabled_cluster + // for more details. + final ScheduledChore authChore = AuthUtil.getAuthChore(conf); + if (authChore != null) { + choreService = new ChoreService("CANARY_TOOL"); + choreService.scheduleChore(authChore); + } + // Start to prepare the stuffs Monitor monitor = null; Thread monitorThread = null; @@ -465,6 +475,9 @@ public final class Canary implements Tool { } while (interval > 0); } // try-with-resources close + if (choreService != null) { + choreService.shutdown(); + } return(monitor.errorCode); } @@ -875,11 +888,6 @@ public final class Canary implements Tool { public static void main(String[] args) throws Exception { final Configuration conf = HBaseConfiguration.create(); - final ChoreService choreService = new ChoreService("CANARY_TOOL"); - final ScheduledChore authChore = AuthUtil.getAuthChore(conf); - if (authChore != null) { - choreService.scheduleChore(authChore); - } int numThreads = conf.getInt("hbase.canary.threads.num", MAX_THREADS_NUM); ExecutorService executor = new ScheduledThreadPoolExecutor(numThreads); @@ -888,7 +896,6 @@ public final class Canary implements Tool { Sink sink = ReflectionUtils.newInstance(sinkClass); int exitCode = ToolRunner.run(conf, new Canary(executor, sink), args); - choreService.shutdown(); executor.shutdown(); System.exit(exitCode); }