NamedClusterProvider extends HDFSFileProvider implements VfsEmbeddedFileSystemCloser { @Override protected FileSystem doCreateFileSystem( FileName name, FileSystemOptions fileSystemOptions ) throws FileSystemException { GenericFileName genericFileName = (GenericFileName) name.getRoot(); String clusterName = genericFileName.getHostName(); String path = genericFileName.getPath(); NamedCluster namedCluster = getNamedClusterByName( clusterName, fileSystemOptions ); try { if ( namedCluster == null ) { namedCluster = namedClusterService.getClusterTemplate(); } String generatedUrl = namedCluster .processURLsubstitution( path == null ? "" : path, getMetastore( clusterName, fileSystemOptions ), new Variables() ); URI uri = URI.create( generatedUrl ); return new NamedClusterFileSystem( name, uri, fileSystemOptions, hadoopFileSystemLocator.getHadoopFilesystem( namedCluster, uri ) ); } catch ( ClusterInitializationException e ) { throw new FileSystemException( e ); } } NamedClusterProvider( HadoopFileSystemLocator hadoopFileSystemLocator,
                               NamedClusterService namedClusterService,
                               FileNameParser fileNameParser,
                               String[] schemes,
                               MetastoreLocatorOsgi metaStore );  NamedClusterProvider( HadoopFileSystemLocator hadoopFileSystemLocator,
                               NamedClusterService namedClusterService,
                               FileNameParser fileNameParser,
                               String schema,
                               MetastoreLocatorOsgi metaStore );  NamedClusterProvider( HadoopFileSystemLocator hadoopFileSystemLocator,
                               NamedClusterService namedClusterService,
                               DefaultFileSystemManager fileSystemManager,
                               FileNameParser fileNameParser,
                               String[] schemes,
                               MetastoreLocatorOsgi metaStore ); @Override FileSystemConfigBuilder getConfigBuilder(); void closeFileSystem( String embeddedMetastoreKey );  }
@Test public void testDoCreateFileSystem() throws FileSystemException, MetaStoreException, ClusterInitializationException { when( metastoreLocator.getMetastore() ).thenReturn( metastore ); UrlFileName name = new UrlFileName( "hc", ncName, 0, 0, null, null, path, null, null ); NamedClusterProvider provider = new NamedClusterProvider( hdfsLocator, ncService, fileSystemManager, fileNameParser, scheme, metastoreLocator ); FileSystem fs = provider.doCreateFileSystem( name, null ); assertTrue( fs instanceof HDFSFileSystem ); HDFSFileSystem hdfsFS = (HDFSFileSystem) fs; assertEquals( hfs, hdfsFS.getHDFSFileSystem() ); verify( nc ).processURLsubstitution( anyString(), eq( metastore ), any( Variables.class ) ); verify( hdfsLocator ).getHadoopFilesystem( eq( nc ), any( URI.class ) ); }
@Test public void testDoCreateFileSystem_NCTemplate() throws FileSystemException, MetaStoreException, ClusterInitializationException { UrlFileName name = new UrlFileName( "hc", ncName, 0, 0, null, null, path, null, null ); NamedClusterProvider provider = new NamedClusterProvider( hdfsLocator, ncService, fileSystemManager, fileNameParser, scheme, metastoreLocator ); FileSystem fs = provider.doCreateFileSystem( name, null ); assertTrue( fs instanceof HDFSFileSystem ); HDFSFileSystem hdfsFS = (HDFSFileSystem) fs; assertEquals( hfs, hdfsFS.getHDFSFileSystem() ); verify( ncService, never() ).read( eq( ncName ), eq( metastore ) ); verify( hdfsLocator ).getHadoopFilesystem( eq( ncTemplate ), any( URI.class ) ); }