HBaseTimelineStorageUtils { public static Configuration getTimelineServiceHBaseConf(Configuration conf) throws IOException { if (conf == null) { throw new NullPointerException(); } Configuration hbaseConf; String timelineServiceHBaseConfFilePath = conf.get(YarnConfiguration.TIMELINE_SERVICE_HBASE_CONFIGURATION_FILE); if (timelineServiceHBaseConfFilePath != null && timelineServiceHBaseConfFilePath.length() > 0) { LOG.info("Using hbase configuration at " + timelineServiceHBaseConfFilePath); hbaseConf = new Configuration(conf); Configuration plainHBaseConf = new Configuration(false); Path hbaseConfigPath = new Path(timelineServiceHBaseConfFilePath); try (FileSystem fs = FileSystem.newInstance(hbaseConfigPath.toUri(), conf); FSDataInputStream in = fs.open(hbaseConfigPath)) { plainHBaseConf.addResource(in); HBaseConfiguration.merge(hbaseConf, plainHBaseConf); } } else { hbaseConf = HBaseConfiguration.create(conf); } return hbaseConf; } private  HBaseTimelineStorageUtils(); static Configuration getTimelineServiceHBaseConf(Configuration conf); static byte[] calculateTheClosestNextRowKeyForPrefix(
      byte[] rowKeyPrefix); static void setMetricsTimeRange(Query query, byte[] metricsCf,
      long tsBegin, long tsEnd);  }
@Test(expected=NullPointerException.class) public void testGetTimelineServiceHBaseConfNullArgument() throws Exception { HBaseTimelineStorageUtils.getTimelineServiceHBaseConf(null); }
@Test public void testWithHbaseConfAtLocalFileSystem() throws IOException { Configuration conf = new Configuration(); conf.set(YarnConfiguration.TIMELINE_SERVICE_HBASE_CONFIGURATION_FILE, hbaseConfigPath); Configuration hbaseConfFromLocal = HBaseTimelineStorageUtils.getTimelineServiceHBaseConf(conf); Assert.assertEquals("Failed to read hbase config from Local FileSystem", "test", hbaseConfFromLocal.get("input")); }
@Test public void testWithHbaseConfAtHdfsFileSystem() throws IOException { MiniDFSCluster hdfsCluster = null; try { HdfsConfiguration hdfsConfig = new HdfsConfiguration(); hdfsCluster = new MiniDFSCluster.Builder(hdfsConfig) .numDataNodes(1).build(); FileSystem fs = hdfsCluster.getFileSystem(); Path path = new Path("/tmp/hdfs-site.xml"); fs.copyFromLocalFile(new Path(hbaseConfigPath), path); Configuration conf = new Configuration(hdfsConfig); conf.set(YarnConfiguration.TIMELINE_SERVICE_HBASE_CONFIGURATION_FILE, path.toString()); Configuration hbaseConfFromHdfs = HBaseTimelineStorageUtils.getTimelineServiceHBaseConf(conf); Assert.assertEquals("Failed to read hbase config from Hdfs FileSystem", "test", hbaseConfFromHdfs.get("input")); } finally { if (hdfsCluster != null) { hdfsCluster.shutdown(); } } }