IGNITE-3163: Implemented.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/374779ca Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/374779ca Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/374779ca Branch: refs/heads/ignite-3163 Commit: 374779ca37781d327f8ba23a0b004519944fe399 Parents: 27564aa Author: vozerov-gridgain <[email protected]> Authored: Thu May 19 12:37:12 2016 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Thu May 19 12:37:12 2016 +0300 ---------------------------------------------------------------------- .../hadoop/fs/BasicHadoopFileSystemFactory.java | 26 +++++++++++++++++++- .../fs/KerberosHadoopFileSystemFactory.java | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/374779ca/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/BasicHadoopFileSystemFactory.java ---------------------------------------------------------------------- diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/BasicHadoopFileSystemFactory.java b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/BasicHadoopFileSystemFactory.java index 01fe6c9..6fbc91c 100644 --- a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/BasicHadoopFileSystemFactory.java +++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/BasicHadoopFileSystemFactory.java @@ -19,10 +19,12 @@ package org.apache.ignite.hadoop.fs; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; import org.apache.ignite.IgniteException; import org.apache.ignite.hadoop.fs.v1.IgniteHadoopFileSystem; import org.apache.ignite.internal.processors.hadoop.HadoopUtils; import org.apache.ignite.internal.processors.igfs.IgfsUtils; +import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lifecycle.LifecycleAware; import org.jetbrains.annotations.Nullable; @@ -57,6 +59,9 @@ public class BasicHadoopFileSystemFactory implements HadoopFileSystemFactory, Ex /** Resulting URI. */ protected transient URI fullUri; + /** Optional working directory. */ + protected transient Path workDir; + /** * Constructor. */ @@ -115,7 +120,7 @@ public class BasicHadoopFileSystemFactory implements HadoopFileSystemFactory, Ex * @throws InterruptedException if the current thread is interrupted. */ protected FileSystem create(String usrName) throws IOException, InterruptedException { - return FileSystem.get(fullUri, cfg, usrName); + return withWorkingDirectory(FileSystem.get(fullUri, cfg, usrName)); } /** @@ -168,6 +173,19 @@ public class BasicHadoopFileSystemFactory implements HadoopFileSystemFactory, Ex this.cfgPaths = cfgPaths; } + /** + * Return file system with correct working directory set. + * + * @param fs File system. + * @return File system with working directory. + */ + protected FileSystem withWorkingDirectory(FileSystem fs) { + if (workDir != null) + fs.setWorkingDirectory(workDir); + + return fs; + } + /** {@inheritDoc} */ @Override public void start() throws IgniteException { cfg = HadoopUtils.safeCreateConfiguration(); @@ -201,6 +219,12 @@ public class BasicHadoopFileSystemFactory implements HadoopFileSystemFactory, Ex throw new IgniteException("Failed to resolve secondary file system URI: " + uri); } } + + // Initialize working directory if needed (ignore empty or "/" paths), + String workDirPath = fullUri.getPath(); + + if (!F.isEmpty(workDirPath) && !F.eq("/", workDirPath)) + workDir = new Path(workDirPath); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/ignite/blob/374779ca/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/KerberosHadoopFileSystemFactory.java ---------------------------------------------------------------------- diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/KerberosHadoopFileSystemFactory.java b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/KerberosHadoopFileSystemFactory.java index a78cabc..10d22d4 100644 --- a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/KerberosHadoopFileSystemFactory.java +++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/KerberosHadoopFileSystemFactory.java @@ -81,7 +81,7 @@ public class KerberosHadoopFileSystemFactory extends BasicHadoopFileSystemFactor return proxyUgi.doAs(new PrivilegedExceptionAction<FileSystem>() { @Override public FileSystem run() throws Exception { - return FileSystem.get(fullUri, cfg); + return withWorkingDirectory(FileSystem.get(fullUri, cfg)); } }); }
