HBASE-12337 Import tool fails with NullPointerException if clusterIds is not initialized

This commit is contained in:
tedyu 2014-11-18 09:18:25 -08:00
parent 3f6b734635
commit 0eb07609b6
1 changed files with 8 additions and 0 deletions

View File

@ -231,18 +231,26 @@ public class Import extends Configured implements Tool {
} }
// TODO: This is kind of ugly doing setup of ZKW just to read the clusterid. // TODO: This is kind of ugly doing setup of ZKW just to read the clusterid.
ZooKeeperWatcher zkw = null; ZooKeeperWatcher zkw = null;
Exception ex = null;
try { try {
zkw = new ZooKeeperWatcher(conf, context.getTaskAttemptID().toString(), null); zkw = new ZooKeeperWatcher(conf, context.getTaskAttemptID().toString(), null);
clusterIds = Collections.singletonList(ZKClusterId.getUUIDForCluster(zkw)); clusterIds = Collections.singletonList(ZKClusterId.getUUIDForCluster(zkw));
} catch (ZooKeeperConnectionException e) { } catch (ZooKeeperConnectionException e) {
ex = e;
LOG.error("Problem connecting to ZooKeper during task setup", e); LOG.error("Problem connecting to ZooKeper during task setup", e);
} catch (KeeperException e) { } catch (KeeperException e) {
ex = e;
LOG.error("Problem reading ZooKeeper data during task setup", e); LOG.error("Problem reading ZooKeeper data during task setup", e);
} catch (IOException e) { } catch (IOException e) {
ex = e;
LOG.error("Problem setting up task", e); LOG.error("Problem setting up task", e);
} finally { } finally {
if (zkw != null) zkw.close(); if (zkw != null) zkw.close();
} }
if (clusterIds == null) {
// exit early if setup fails
throw new RuntimeException(ex);
}
} }
} }