IGNITE-2206: Finalization.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/7915c12e Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/7915c12e Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/7915c12e Branch: refs/heads/ignite-2206 Commit: 7915c12e615faa33bb2761d5cd928b3442b2110c Parents: 262af69 Author: vozerov-gridgain <voze...@gridgain.com> Authored: Wed Dec 23 18:24:13 2015 +0300 Committer: vozerov-gridgain <voze...@gridgain.com> Committed: Wed Dec 23 18:24:13 2015 +0300 ---------------------------------------------------------------------- .../hadoop/fs/BasicHadoopFileSystemFactory.java | 30 +++++------ .../hadoop/fs/HadoopFileSystemFactory.java | 6 +-- .../fs/IgniteHadoopIgfsSecondaryFileSystem.java | 55 ++++++++++---------- 3 files changed, 45 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/7915c12e/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 a2317cf..bc22da8 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 @@ -36,7 +36,7 @@ import java.net.URL; import java.util.Arrays; /** - * Caching Hadoop file system factory. File systems are cache on per-user basis. + * Simple Hadoop file system factory factory which delegates to {@code FileSystem.get()}. */ public class BasicHadoopFileSystemFactory implements HadoopFileSystemFactory, Externalizable, LifecycleAware { /** File system URI. */ @@ -46,10 +46,10 @@ public class BasicHadoopFileSystemFactory implements HadoopFileSystemFactory, Ex protected String[] cfgPaths; /** Configuration of the secondary filesystem, never null. */ - protected Configuration cfg; + protected transient Configuration cfg; /** */ - protected URI fullUri; + protected transient URI fullUri; /** * Public non-arg constructor. @@ -121,18 +121,6 @@ public class BasicHadoopFileSystemFactory implements HadoopFileSystemFactory, Ex /** {@inheritDoc} */ @Override public void start() throws IgniteException { - // if secondary fs URI is not given explicitly, try to get it from the configuration: - if (uri == null) - fullUri = FileSystem.getDefaultUri(cfg); - else { - try { - fullUri = new URI(uri); - } - catch (URISyntaxException use) { - throw new IgniteException("Failed to resolve secondary file system URI: " + uri); - } - } - cfg = HadoopUtils.safeCreateConfiguration(); if (cfgPaths != null) { @@ -152,6 +140,18 @@ public class BasicHadoopFileSystemFactory implements HadoopFileSystemFactory, Ex } } } + + // If secondary fs URI is not given explicitly, try to get it from the configuration: + if (uri == null) + fullUri = FileSystem.getDefaultUri(cfg); + else { + try { + fullUri = new URI(uri); + } + catch (URISyntaxException use) { + throw new IgniteException("Failed to resolve secondary file system URI: " + uri); + } + } } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/ignite/blob/7915c12e/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/HadoopFileSystemFactory.java ---------------------------------------------------------------------- diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/HadoopFileSystemFactory.java b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/HadoopFileSystemFactory.java index b4edab8..3298ddd 100644 --- a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/HadoopFileSystemFactory.java +++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/HadoopFileSystemFactory.java @@ -22,7 +22,7 @@ import java.io.Serializable; import org.apache.hadoop.fs.FileSystem; /** - * This factory is {@link Serializable} because it should be transferable over the network. + * Hadoop file system factory. Used to construct instance of {@link FileSystem} for Ignite. * <p> * Implementations may choose not to construct a new instance, but instead * return a previously created instance. @@ -33,9 +33,9 @@ public interface HadoopFileSystemFactory extends Serializable { * All the other data needed for the file system creation are expected to be contained * in this object instance. * - * @param userName The user name + * @param usrName The user name * @return The file system. * @throws IOException On error. */ - public FileSystem create(String userName) throws IOException; + public FileSystem create(String usrName) throws IOException; } http://git-wip-us.apache.org/repos/asf/ignite/blob/7915c12e/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/IgniteHadoopIgfsSecondaryFileSystem.java ---------------------------------------------------------------------- diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/IgniteHadoopIgfsSecondaryFileSystem.java b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/IgniteHadoopIgfsSecondaryFileSystem.java index 99b8f5a..98dc20e 100644 --- a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/IgniteHadoopIgfsSecondaryFileSystem.java +++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/IgniteHadoopIgfsSecondaryFileSystem.java @@ -43,7 +43,6 @@ import org.apache.ignite.internal.processors.igfs.IgfsFileImpl; import org.apache.ignite.internal.processors.igfs.IgfsFileInfo; import org.apache.ignite.internal.processors.igfs.IgfsUtils; import org.apache.ignite.internal.util.typedef.F; -import org.apache.ignite.internal.util.typedef.internal.A; import org.apache.ignite.lifecycle.LifecycleAware; import org.jetbrains.annotations.Nullable; @@ -68,16 +67,16 @@ import static org.apache.ignite.internal.processors.igfs.IgfsEx.PROP_USER_NAME; public class IgniteHadoopIgfsSecondaryFileSystem implements IgfsSecondaryFileSystem, LifecycleAware, HadoopPayloadAware { /** The default user name. It is used if no user context is set. */ - private @Nullable String dfltUsrName; + private String dfltUsrName; - /** */ + /** Factory. */ private HadoopFileSystemFactory fsFactory; /** * Default constructor for Spring. */ public IgniteHadoopIgfsSecondaryFileSystem() { - // noop. + // No-op. } /** @@ -109,14 +108,16 @@ public class IgniteHadoopIgfsSecondaryFileSystem implements IgfsSecondaryFileSys * * @param uri URI of file system. * @param cfgPath Additional path to Hadoop configuration. - * @param userName User name. + * @param usrName User name. * @throws IgniteCheckedException In case of error. * @deprecated Arg-less constructor should be used instead, + setters. This constructor is * supported for compatibility only. */ @Deprecated public IgniteHadoopIgfsSecondaryFileSystem(@Nullable String uri, @Nullable String cfgPath, - @Nullable String userName) throws IgniteCheckedException { + @Nullable String usrName) throws IgniteCheckedException { + setDefaultUserName(usrName); + CachingHadoopFileSystemFactory fac = new CachingHadoopFileSystemFactory(); fac.setUri(uri); @@ -125,45 +126,42 @@ public class IgniteHadoopIgfsSecondaryFileSystem implements IgfsSecondaryFileSys fac.setConfigPaths(cfgPath); setFileSystemFactory(fac); - setDefaultUserName(userName); } /** - * Sets secondary file system factory. + * Gets the default user name. * - * @param factory The factory to set. + * @return The default user name. */ - public void setFileSystemFactory(HadoopFileSystemFactory factory) { - A.ensure(factory != null, "Factory value must not be null."); - - this.fsFactory = factory; + public String getDefaultUserName() { + return dfltUsrName; } /** - * Gets the secondary file system factory. + * Sets the default user name. * - * @return The secondary file system factory. + * @param dfltUsrName The user name to set. */ - public HadoopFileSystemFactory getFileSystemFactory() { - return fsFactory; + public void setDefaultUserName(String dfltUsrName) { + this.dfltUsrName = dfltUsrName; } /** - * Sets the default user name. + * Gets the secondary file system factory. * - * @param usrName The user name to set. + * @return The secondary file system factory. */ - public void setDefaultUserName(String usrName) { - this.dfltUsrName = usrName; + public HadoopFileSystemFactory getFileSystemFactory() { + return fsFactory; } /** - * Gets the default user name. + * Sets secondary file system factory. * - * @return The default user name. + * @param factory The factory to set. */ - public String getDefaultUserName() { - return dfltUsrName; + public void setFileSystemFactory(HadoopFileSystemFactory factory) { + this.fsFactory = factory; } /** @@ -510,9 +508,10 @@ public class IgniteHadoopIgfsSecondaryFileSystem implements IgfsSecondaryFileSys /** {@inheritDoc} */ @Override public void start() throws IgniteException { - // #start() should not ever be invoked if these properties are not set: - A.ensure(fsFactory != null, "factory"); - A.ensure(dfltUsrName != null, "userName"); + dfltUsrName = IgfsUtils.fixUserName(dfltUsrName); + + if (fsFactory == null) + fsFactory = new CachingHadoopFileSystemFactory(); if (fsFactory instanceof LifecycleAware) ((LifecycleAware) fsFactory).start();