@@ -98,107 +98,133 @@ public String getScheme() {
9898
9999 @ Override
100100 public void initialize (URI theUri , Configuration conf ) throws IOException {
101+ this .myUri = theUri ;
101102 if (LOG .isDebugEnabled ()) {
102103 LOG .debug ("Initializing the ViewFileSystemOverloadScheme with the uri: "
103104 + theUri );
104105 }
105- this .myUri = theUri ;
106+ String mountTableConfigPath =
107+ conf .get (Constants .CONFIG_VIEWFS_MOUNTTABLE_PATH );
108+ if (null != mountTableConfigPath ) {
109+ MountTableConfigLoader loader = new HCFSMountTableConfigLoader ();
110+ loader .load (mountTableConfigPath , conf );
111+ } else {
112+ // TODO: Should we fail here.?
113+ if (LOG .isDebugEnabled ()) {
114+ LOG .debug (
115+ "Missing configuration for fs.viewfs.mounttable.path. Proceeding"
116+ + "with core-site.xml mount-table information if avaialable." );
117+ }
118+ }
106119 super .initialize (theUri , conf );
107120 }
108121
109122 /**
110123 * This method is overridden because in ViewFileSystemOverloadScheme if
111- * overloaded cheme matches with mounted target fs scheme, file system should
112- * be created without going into fs.<scheme>.impl based resolution. Otherwise
113- * it will end up in an infinite loop as the target will be resolved again
114- * to ViewFileSystemOverloadScheme as fs.<scheme>.impl points to
115- * ViewFileSystemOverloadScheme. So, below method will initialize the
124+ * overloaded scheme matches with mounted target fs scheme, file system
125+ * should be created without going into fs.<scheme>.impl based resolution.
126+ * Otherwise it will end up in an infinite loop as the target will be
127+ * resolved again to ViewFileSystemOverloadScheme as fs.<scheme>.impl points
128+ * to ViewFileSystemOverloadScheme. So, below method will initialize the
116129 * fs.viewfs.overload.scheme.target.<scheme>.impl. Other schemes can
117130 * follow fs.newInstance
118131 */
119132 @ Override
120133 protected FsGetter fsGetter () {
134+ return new ChildFsGetter (getScheme ());
135+ }
121136
122- return new FsGetter () {
123- @ Override
124- public FileSystem getNewInstance (URI uri , Configuration conf )
125- throws IOException {
126- if (uri .getScheme ().equals (getScheme ())) {
127- if (LOG .isDebugEnabled ()) {
128- LOG .debug (
129- "The file system initialized uri scheme is matching with the "
130- + "given target uri scheme. The target uri is: " + uri );
131- }
132- /*
133- * Avoid looping when target fs scheme is matching to overloaded
134- * scheme.
135- */
136- return createFileSystem (uri , conf );
137- } else {
138- return FileSystem .newInstance (uri , conf );
137+ /**
138+ * This class checks whether the rooScheme is same as URI scheme. If both are
139+ * same, then it will initialize file systems by using the configured
140+ * fs.viewfs.overload.scheme.target.<scheme>.impl class.
141+ */
142+ static class ChildFsGetter extends FsGetter {
143+
144+ private final String rootScheme ;
145+
146+ ChildFsGetter (String rootScheme ) {
147+ this .rootScheme = rootScheme ;
148+ }
149+
150+ @ Override
151+ public FileSystem getNewInstance (URI uri , Configuration conf )
152+ throws IOException {
153+ if (uri .getScheme ().equals (this .rootScheme )) {
154+ if (LOG .isDebugEnabled ()) {
155+ LOG .debug (
156+ "The file system initialized uri scheme is matching with the "
157+ + "given target uri scheme. The target uri is: " + uri );
139158 }
159+ /*
160+ * Avoid looping when target fs scheme is matching to overloaded scheme.
161+ */
162+ return createFileSystem (uri , conf );
163+ } else {
164+ return FileSystem .newInstance (uri , conf );
140165 }
166+ }
141167
142- /**
143- * When ViewFileSystemOverloadScheme scheme and target uri scheme are
144- * matching, it will not take advantage of FileSystem cache as it will
145- * create instance directly. For caching needs please set
146- * "fs.viewfs.enable.inner.cache" to true.
147- */
148- @ Override
149- public FileSystem get (URI uri , Configuration conf ) throws IOException {
150- if (uri .getScheme ().equals (getScheme ())) {
151- // Avoid looping when target fs scheme is matching to overloaded
152- // scheme.
153- if (LOG .isDebugEnabled ()) {
154- LOG .debug (
155- "The file system initialized uri scheme is matching with the "
156- + "given target uri scheme. So, the target file system "
157- + "instances will not be cached. To cache fs instances, "
158- + "please set fs.viewfs.enable.inner.cache to true. "
159- + "The target uri is: " + uri );
160- }
161- return createFileSystem (uri , conf );
162- } else {
163- return FileSystem .get (uri , conf );
168+ /**
169+ * When ViewFileSystemOverloadScheme scheme and target uri scheme are
170+ * matching, it will not take advantage of FileSystem cache as it will
171+ * create instance directly. For caching needs please set
172+ * "fs.viewfs.enable.inner.cache" to true.
173+ */
174+ @ Override
175+ public FileSystem get (URI uri , Configuration conf ) throws IOException {
176+ if (uri .getScheme ().equals (this .rootScheme )) {
177+ // Avoid looping when target fs scheme is matching to overloaded
178+ // scheme.
179+ if (LOG .isDebugEnabled ()) {
180+ LOG .debug (
181+ "The file system initialized uri scheme is matching with the "
182+ + "given target uri scheme. So, the target file system "
183+ + "instances will not be cached. To cache fs instances, "
184+ + "please set fs.viewfs.enable.inner.cache to true. "
185+ + "The target uri is: " + uri );
164186 }
187+ return createFileSystem (uri , conf );
188+ } else {
189+ return FileSystem .get (uri , conf );
165190 }
191+ }
166192
167- private FileSystem createFileSystem (URI uri , Configuration conf )
168- throws IOException {
169- final String fsImplConf = String .format (
170- FsConstants .FS_VIEWFS_OVERLOAD_SCHEME_TARGET_FS_IMPL_PATTERN ,
171- uri .getScheme ());
172- Class <?> clazz = conf .getClass (fsImplConf , null );
173- if (clazz == null ) {
174- throw new UnsupportedFileSystemException (
175- String .format ("%s=null: %s: %s" , fsImplConf ,
176- "No overload scheme fs configured" , uri .getScheme ()));
177- }
178- FileSystem fs = (FileSystem ) newInstance (clazz , uri , conf );
179- fs .initialize (uri , conf );
180- return fs ;
193+ private FileSystem createFileSystem (URI uri , Configuration conf )
194+ throws IOException {
195+ final String fsImplConf = String .format (
196+ FsConstants .FS_VIEWFS_OVERLOAD_SCHEME_TARGET_FS_IMPL_PATTERN ,
197+ uri .getScheme ());
198+ Class <?> clazz = conf .getClass (fsImplConf , null );
199+ if (clazz == null ) {
200+ throw new UnsupportedFileSystemException (
201+ String .format ("%s=null: %s: %s" , fsImplConf ,
202+ "No overload scheme fs configured" , uri .getScheme ()));
181203 }
204+ FileSystem fs = (FileSystem ) newInstance (clazz , uri , conf );
205+ fs .initialize (uri , conf );
206+ return fs ;
207+ }
182208
183- private <T > T newInstance (Class <T > theClass , URI uri ,
184- Configuration conf ) {
185- T result ;
186- try {
187- Constructor <T > meth = theClass .getConstructor ();
188- meth .setAccessible (true );
189- result = meth .newInstance ();
190- } catch (InvocationTargetException e ) {
191- Throwable cause = e .getCause ();
192- if (cause instanceof RuntimeException ) {
193- throw (RuntimeException ) cause ;
194- } else {
195- throw new RuntimeException (cause );
196- }
197- } catch (Exception e ) {
198- throw new RuntimeException (e );
209+ private <T > T newInstance (Class <T > theClass , URI uri , Configuration conf ) {
210+ T result ;
211+ try {
212+ Constructor <T > meth = theClass .getConstructor ();
213+ meth .setAccessible (true );
214+ result = meth .newInstance ();
215+ } catch (InvocationTargetException e ) {
216+ Throwable cause = e .getCause ();
217+ if (cause instanceof RuntimeException ) {
218+ throw (RuntimeException ) cause ;
219+ } else {
220+ throw new RuntimeException (cause );
199221 }
200- return result ;
222+ } catch (Exception e ) {
223+ throw new RuntimeException (e );
201224 }
202- };
225+ return result ;
226+ }
227+
203228 }
229+
204230}
0 commit comments