FileSystemAccessService extends BaseService implements FileSystemAccess { protected FileSystem createFileSystem(Configuration namenodeConf) throws IOException { String user = UserGroupInformation.getCurrentUser().getShortUserName(); CachedFileSystem newCachedFS = new CachedFileSystem(purgeTimeout); CachedFileSystem cachedFS = fsCache.putIfAbsent(user, newCachedFS); if (cachedFS == null) { cachedFS = newCachedFS; } Configuration conf = new Configuration(namenodeConf); conf.set(HTTPFS_FS_USER, user); return cachedFS.getFileSytem(conf); } FileSystemAccessService(); @Override void postInit(); @Override Class getInterface(); @Override Class[] getServiceDependencies(); @Override T execute(String user, final Configuration conf,
      final FileSystemExecutor<T> executor); FileSystem createFileSystemInternal(String user,
      final Configuration conf); @Override FileSystem createFileSystem(String user, final Configuration conf); @Override void releaseFileSystem(FileSystem fs); @Override Configuration getFileSystemConfiguration(); static final String PREFIX; static final String AUTHENTICATION_TYPE; static final String KERBEROS_KEYTAB; static final String KERBEROS_PRINCIPAL; static final String FS_CACHE_PURGE_FREQUENCY; static final String FS_CACHE_PURGE_TIMEOUT; static final String NAME_NODE_WHITELIST; static final String HADOOP_CONF_DIR; }
@Test @TestDir @TestHdfs public void createFileSystem() throws Exception { String dir = TestDirHelper.getTestDir().getAbsolutePath(); String services = StringUtils.join(",", Arrays .asList(InstrumentationService.class.getName(), SchedulerService.class.getName(), FileSystemAccessService.class.getName())); Configuration hadoopConf = new Configuration(false); hadoopConf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, TestHdfsHelper.getHdfsConf() .get(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY)); createHadoopConf(hadoopConf); Configuration conf = new Configuration(false); conf.set("server.services", services); conf.set("server.hadoop.filesystem.cache.purge.timeout", "0"); Server server = new Server("server", dir, dir, dir, dir, conf); server.init(); FileSystemAccess hadoop = server.get(FileSystemAccess.class); FileSystem fs = hadoop.createFileSystem("u", hadoop.getFileSystemConfiguration()); Assert.assertNotNull(fs); fs.mkdirs(new Path("/tmp/foo")); hadoop.releaseFileSystem(fs); try { fs.mkdirs(new Path("/tmp/foo")); Assert.fail(); } catch (IOException ex) { } catch (Exception ex) { Assert.fail(); } server.destroy(); }