@Override public void serviceInit(Configuration conf) throws Exception { this.allocFile = getAllocationFile(conf); if (allocFile != null) { reloadThread = new Thread() {
@Override public void serviceInit(Configuration conf) throws Exception { this.allocFile = getAllocationFile(conf); if (allocFile != null) { reloadThread = new Thread() {
@Override public void serviceInit(Configuration conf) throws Exception { this.allocFile = getAllocationFile(conf); if (this.allocFile != null) { this.fs = allocFile.getFileSystem(conf);
@Test public void testGetAllocationFileFromClasspath() { Configuration conf = new Configuration(); conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, "test-fair-scheduler.xml"); AllocationFileLoaderService allocLoader = new AllocationFileLoaderService(); File allocationFile = allocLoader.getAllocationFile(conf); assertEquals("test-fair-scheduler.xml", allocationFile.getName()); assertTrue(allocationFile.exists()); }
@Test (expected = UnsupportedFileSystemException.class) public void testDenyGetAllocationFileFromUnsupportedFileSystem() throws UnsupportedFileSystemException { Configuration conf = new YarnConfiguration(); conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, "badfs:///badfile"); AllocationFileLoaderService allocLoader = new AllocationFileLoaderService(); allocLoader.getAllocationFile(conf); }
@Test public void testGetAllocationFileFromClasspath() { try { Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf); conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, TEST_FAIRSCHED_XML); AllocationFileLoaderService allocLoader = new AllocationFileLoaderService(); Path allocationFile = allocLoader.getAllocationFile(conf); assertEquals(TEST_FAIRSCHED_XML, allocationFile.getName()); assertTrue(fs.exists(allocationFile)); } catch (IOException e) { fail("Unable to access allocation file from classpath: " + e); } }
@Test public void testGetAllocationFileFromFileSystem() throws IOException, URISyntaxException { Configuration conf = new YarnConfiguration(); File baseDir = new File(TEST_DIR + Path.SEPARATOR + "getAllocHDFS").getAbsoluteFile(); FileUtil.fullyDelete(baseDir); conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, baseDir.getAbsolutePath()); MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(conf); MiniDFSCluster hdfsCluster = builder.build(); String fsAllocPath = "hdfs://localhost:" + hdfsCluster.getNameNodePort() + Path.SEPARATOR + TEST_FAIRSCHED_XML; URL fschedURL = Thread.currentThread().getContextClassLoader() .getResource(TEST_FAIRSCHED_XML); FileSystem fs = FileSystem.get(conf); fs.copyFromLocalFile(new Path(fschedURL.toURI()), new Path(fsAllocPath)); conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, fsAllocPath); AllocationFileLoaderService allocLoader = new AllocationFileLoaderService(); Path allocationFile = allocLoader.getAllocationFile(conf); assertEquals(fsAllocPath, allocationFile.toString()); assertTrue(fs.exists(allocationFile)); hdfsCluster.shutdown(true); }