ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [59/92] [abbrv] ignite git commit: Proper Hadoop secondary file system initialization.
Date Wed, 21 Sep 2016 14:53:51 GMT
Proper Hadoop secondary file system initialization.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2b6c36eb
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2b6c36eb
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2b6c36eb

Branch: refs/heads/ignite-3949
Commit: 2b6c36ebae2a1f5afd54fe34e9f37aed6744dc2a
Parents: 99cb18b
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Wed Sep 21 15:09:13 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Wed Sep 21 15:09:13 2016 +0300

----------------------------------------------------------------------
 .../internal/processors/igfs/IgfsImpl.java      |  5 ++-
 .../processors/igfs/IgfsKernalContextAware.java | 32 ++++++++++++++++++
 .../processors/hadoop/impl/HadoopUtils.java     | 35 ++------------------
 .../HadoopBasicFileSystemFactoryDelegate.java   |  5 +--
 .../processors/hadoop/impl/v2/HadoopV2Job.java  | 13 ++++----
 .../impl/v2/HadoopV2JobResourceManager.java     |  5 +--
 .../hadoop/impl/v2/HadoopV2TaskContext.java     | 13 ++++----
 .../fs/IgniteHadoopIgfsSecondaryFileSystem.java | 31 ++++++++++++++---
 .../processors/hadoop/HadoopCommonUtils.java    | 30 +++++++++++++++--
 .../hadoop/delegate/HadoopDelegateUtils.java    | 16 +++++----
 10 files changed, 123 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/2b6c36eb/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
index 45596a3..c379c09 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
@@ -182,8 +182,11 @@ public final class IgfsImpl implements IgfsEx {
         data = igfsCtx.data();
         secondaryFs = cfg.getSecondaryFileSystem();
 
+        if (secondaryFs instanceof IgfsKernalContextAware)
+            ((IgfsKernalContextAware)secondaryFs).setKernalContext(igfsCtx.kernalContext());
+
         if (secondaryFs instanceof LifecycleAware)
-            ((LifecycleAware) secondaryFs).start();
+            ((LifecycleAware)secondaryFs).start();
 
         /* Default IGFS mode. */
         IgfsMode dfltMode;

http://git-wip-us.apache.org/repos/asf/ignite/blob/2b6c36eb/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsKernalContextAware.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsKernalContextAware.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsKernalContextAware.java
new file mode 100644
index 0000000..7f59db4
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsKernalContextAware.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.igfs;
+
+import org.apache.ignite.internal.GridKernalContext;
+
+/**
+ * Indicates whether particular file system accepts kernal context.
+ */
+public interface IgfsKernalContextAware {
+    /**
+     * Set kernal context.
+     *
+     * @param ctx Kernal context.
+     */
+    public void setKernalContext(GridKernalContext ctx);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2b6c36eb/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/HadoopUtils.java
----------------------------------------------------------------------
diff --git a/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/HadoopUtils.java
b/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/HadoopUtils.java
index 6ace694..e70129a 100644
--- a/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/HadoopUtils.java
+++ b/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/HadoopUtils.java
@@ -37,12 +37,12 @@ import org.apache.hadoop.mapreduce.JobPriority;
 import org.apache.hadoop.mapreduce.JobStatus;
 import org.apache.hadoop.mapreduce.MRJobConfig;
 import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.processors.hadoop.HadoopCommonUtils;
 import org.apache.ignite.internal.processors.hadoop.HadoopJobId;
 import org.apache.ignite.internal.processors.hadoop.HadoopJobStatus;
 import org.apache.ignite.internal.processors.hadoop.HadoopTaskInfo;
 import org.apache.ignite.internal.processors.hadoop.impl.v2.HadoopSplitWrapper;
 import org.apache.ignite.internal.util.typedef.internal.U;
-import org.jetbrains.annotations.Nullable;
 
 /**
  * Hadoop utility methods.
@@ -326,42 +326,13 @@ public class HadoopUtils {
      * @return New instance of {@link Configuration}.
      */
     public static Configuration safeCreateConfiguration() {
-        final ClassLoader oldLdr = setContextClassLoader(Configuration.class.getClassLoader());
+        final ClassLoader oldLdr = HadoopCommonUtils.setContextClassLoader(Configuration.class.getClassLoader());
 
         try {
             return new Configuration();
         }
         finally {
-            restoreContextClassLoader(oldLdr);
+            HadoopCommonUtils.restoreContextClassLoader(oldLdr);
         }
     }
-
-
-
-    /**
-     * Set context class loader.
-     *
-     * @param newLdr New class loader.
-     * @return Old class loader.
-     */
-    @Nullable public static ClassLoader setContextClassLoader(@Nullable ClassLoader newLdr)
{
-        ClassLoader oldLdr = Thread.currentThread().getContextClassLoader();
-
-        if (newLdr != oldLdr)
-            Thread.currentThread().setContextClassLoader(newLdr);
-
-        return oldLdr;
-    }
-
-    /**
-     * Restore context class loader.
-     *
-     * @param oldLdr Original class loader.
-     */
-    public static void restoreContextClassLoader(@Nullable ClassLoader oldLdr) {
-        ClassLoader newLdr = Thread.currentThread().getContextClassLoader();
-
-        if (newLdr != oldLdr)
-            Thread.currentThread().setContextClassLoader(oldLdr);
-    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/2b6c36eb/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/delegate/HadoopBasicFileSystemFactoryDelegate.java
----------------------------------------------------------------------
diff --git a/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/delegate/HadoopBasicFileSystemFactoryDelegate.java
b/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/delegate/HadoopBasicFileSystemFactoryDelegate.java
index c8d760c..a190b14 100644
--- a/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/delegate/HadoopBasicFileSystemFactoryDelegate.java
+++ b/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/delegate/HadoopBasicFileSystemFactoryDelegate.java
@@ -23,6 +23,7 @@ import org.apache.ignite.IgniteException;
 import org.apache.ignite.hadoop.fs.BasicHadoopFileSystemFactory;
 import org.apache.ignite.hadoop.fs.HadoopFileSystemFactory;
 import org.apache.ignite.hadoop.util.UserNameMapper;
+import org.apache.ignite.internal.processors.hadoop.HadoopCommonUtils;
 import org.apache.ignite.internal.processors.hadoop.delegate.HadoopFileSystemFactoryDelegate;
 import org.apache.ignite.internal.processors.hadoop.impl.HadoopUtils;
 import org.apache.ignite.internal.processors.igfs.IgfsUtils;
@@ -84,13 +85,13 @@ public class HadoopBasicFileSystemFactoryDelegate implements HadoopFileSystemFac
             // FileSystem.get() might delegate to ServiceLoader to get the list of file system
implementation.
             // And ServiceLoader is known to be sensitive to context classloader. Therefore,
we change context
             // classloader to classloader of current class to avoid strange class-cast-exceptions.
-            ClassLoader oldLdr = HadoopUtils.setContextClassLoader(getClass().getClassLoader());
+            ClassLoader oldLdr = HadoopCommonUtils.setContextClassLoader(getClass().getClassLoader());
 
             try {
                 return create(usrName);
             }
             finally {
-                HadoopUtils.restoreContextClassLoader(oldLdr);
+                HadoopCommonUtils.restoreContextClassLoader(oldLdr);
             }
         }
         catch (InterruptedException e) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/2b6c36eb/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/v2/HadoopV2Job.java
----------------------------------------------------------------------
diff --git a/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/v2/HadoopV2Job.java
b/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/v2/HadoopV2Job.java
index ce91b8e..5801c98 100644
--- a/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/v2/HadoopV2Job.java
+++ b/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/v2/HadoopV2Job.java
@@ -50,6 +50,7 @@ import org.apache.hadoop.mapreduce.split.SplitMetaInfoReader;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.internal.processors.hadoop.HadoopClassLoader;
+import org.apache.ignite.internal.processors.hadoop.HadoopCommonUtils;
 import org.apache.ignite.internal.processors.hadoop.impl.HadoopDefaultJobInfo;
 import org.apache.ignite.internal.processors.hadoop.HadoopFileBlock;
 import org.apache.ignite.internal.processors.hadoop.HadoopHelper;
@@ -143,7 +144,7 @@ public class HadoopV2Job implements HadoopJob {
         this.libNames = libNames;
         this.helper = helper;
 
-        ClassLoader oldLdr = HadoopUtils.setContextClassLoader(getClass().getClassLoader());
+        ClassLoader oldLdr = HadoopCommonUtils.setContextClassLoader(getClass().getClassLoader());
 
         try {
             hadoopJobID = new JobID(jobId.globalId().toString(), jobId.localId());
@@ -160,7 +161,7 @@ public class HadoopV2Job implements HadoopJob {
             rsrcMgr = new HadoopV2JobResourceManager(jobId, jobCtx, log, this);
         }
         finally {
-            HadoopUtils.setContextClassLoader(oldLdr);
+            HadoopCommonUtils.restoreContextClassLoader(oldLdr);
         }
     }
 
@@ -176,7 +177,7 @@ public class HadoopV2Job implements HadoopJob {
 
     /** {@inheritDoc} */
     @Override public Collection<HadoopInputSplit> input() throws IgniteCheckedException
{
-        ClassLoader oldLdr = HadoopUtils.setContextClassLoader(jobConf.getClassLoader());
+        ClassLoader oldLdr = HadoopCommonUtils.setContextClassLoader(jobConf.getClassLoader());
 
         try {
             String jobDirPath = jobConf.get(MRJobConfig.MAPREDUCE_JOB_DIR);
@@ -233,7 +234,7 @@ public class HadoopV2Job implements HadoopJob {
             }
         }
         finally {
-            HadoopUtils.restoreContextClassLoader(oldLdr);
+            HadoopCommonUtils.restoreContextClassLoader(oldLdr);
         }
     }
 
@@ -306,13 +307,13 @@ public class HadoopV2Job implements HadoopJob {
 
         this.locNodeId = locNodeId;
 
-        ClassLoader oldLdr = HadoopUtils.setContextClassLoader(getClass().getClassLoader());
+        ClassLoader oldLdr = HadoopCommonUtils.setContextClassLoader(getClass().getClassLoader());
 
         try {
             rsrcMgr.prepareJobEnvironment(!external, jobLocalDir(locNodeId, jobId));
         }
         finally {
-            HadoopUtils.restoreContextClassLoader(oldLdr);
+            HadoopCommonUtils.restoreContextClassLoader(oldLdr);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2b6c36eb/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/v2/HadoopV2JobResourceManager.java
----------------------------------------------------------------------
diff --git a/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/v2/HadoopV2JobResourceManager.java
b/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/v2/HadoopV2JobResourceManager.java
index e459f49..3bbfcd9 100644
--- a/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/v2/HadoopV2JobResourceManager.java
+++ b/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/v2/HadoopV2JobResourceManager.java
@@ -36,6 +36,7 @@ import org.apache.hadoop.mapreduce.MRJobConfig;
 import org.apache.hadoop.util.RunJar;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.processors.hadoop.HadoopCommonUtils;
 import org.apache.ignite.internal.processors.hadoop.HadoopJobId;
 import org.apache.ignite.internal.processors.hadoop.impl.HadoopUtils;
 import org.apache.ignite.internal.processors.hadoop.impl.fs.HadoopFileSystemsUtils;
@@ -95,7 +96,7 @@ class HadoopV2JobResourceManager {
     private void setLocalFSWorkingDirectory(File dir) throws IOException {
         JobConf cfg = ctx.getJobConf();
 
-        ClassLoader oldLdr = HadoopUtils.setContextClassLoader(cfg.getClassLoader());
+        ClassLoader oldLdr = HadoopCommonUtils.setContextClassLoader(cfg.getClassLoader());
 
         try {
             cfg.set(HadoopFileSystemsUtils.LOC_FS_WORK_DIR_PROP, dir.getAbsolutePath());
@@ -104,7 +105,7 @@ class HadoopV2JobResourceManager {
                 FileSystem.getLocal(cfg).setWorkingDirectory(new Path(dir.getAbsolutePath()));
         }
         finally {
-            HadoopUtils.restoreContextClassLoader(oldLdr);
+            HadoopCommonUtils.restoreContextClassLoader(oldLdr);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2b6c36eb/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/v2/HadoopV2TaskContext.java
----------------------------------------------------------------------
diff --git a/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/v2/HadoopV2TaskContext.java
b/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/v2/HadoopV2TaskContext.java
index a7397e4..4d1cf79 100644
--- a/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/v2/HadoopV2TaskContext.java
+++ b/modules/hadoop-impl/src/main/java/org/apache/ignite/internal/processors/hadoop/impl/v2/HadoopV2TaskContext.java
@@ -47,6 +47,7 @@ import org.apache.hadoop.mapreduce.TaskType;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.processors.hadoop.HadoopClassLoader;
+import org.apache.ignite.internal.processors.hadoop.HadoopCommonUtils;
 import org.apache.ignite.internal.processors.hadoop.HadoopInputSplit;
 import org.apache.ignite.internal.processors.hadoop.HadoopJob;
 import org.apache.ignite.internal.processors.hadoop.HadoopJobId;
@@ -159,7 +160,7 @@ public class HadoopV2TaskContext extends HadoopTaskContext {
         this.locNodeId = locNodeId;
 
         // Before create JobConf instance we should set new context class loader.
-        ClassLoader oldLdr = HadoopUtils.setContextClassLoader(getClass().getClassLoader());
+        ClassLoader oldLdr = HadoopCommonUtils.setContextClassLoader(getClass().getClassLoader());
 
         try {
             JobConf jobConf = new JobConf();
@@ -181,7 +182,7 @@ public class HadoopV2TaskContext extends HadoopTaskContext {
             useNewCombiner = jobConf.getCombinerClass() == null;
         }
         finally {
-            HadoopUtils.restoreContextClassLoader(oldLdr);
+            HadoopCommonUtils.restoreContextClassLoader(oldLdr);
         }
     }
 
@@ -230,7 +231,7 @@ public class HadoopV2TaskContext extends HadoopTaskContext {
 
     /** {@inheritDoc} */
     @Override public void run() throws IgniteCheckedException {
-        ClassLoader oldLdr = HadoopUtils.setContextClassLoader(jobConf().getClassLoader());
+        ClassLoader oldLdr = HadoopCommonUtils.setContextClassLoader(jobConf().getClassLoader());
 
         try {
             try {
@@ -259,7 +260,7 @@ public class HadoopV2TaskContext extends HadoopTaskContext {
         finally {
             task = null;
 
-            HadoopUtils.restoreContextClassLoader(oldLdr);
+            HadoopCommonUtils.restoreContextClassLoader(oldLdr);
         }
     }
 
@@ -290,7 +291,7 @@ public class HadoopV2TaskContext extends HadoopTaskContext {
                 locDir = jobLocalDir(locNodeId, taskInfo().jobId());
         }
 
-        ClassLoader oldLdr = HadoopUtils.setContextClassLoader(jobConf().getClassLoader());
+        ClassLoader oldLdr = HadoopCommonUtils.setContextClassLoader(jobConf().getClassLoader());
 
         try {
             FileSystem.get(jobConf());
@@ -306,7 +307,7 @@ public class HadoopV2TaskContext extends HadoopTaskContext {
             throw transformException(e);
         }
         finally {
-            HadoopUtils.restoreContextClassLoader(oldLdr);
+            HadoopCommonUtils.restoreContextClassLoader(oldLdr);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2b6c36eb/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 5fb078a..c9d08c5 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
@@ -24,9 +24,13 @@ import org.apache.ignite.igfs.IgfsFile;
 import org.apache.ignite.igfs.IgfsPath;
 import org.apache.ignite.igfs.IgfsUserContext;
 import org.apache.ignite.igfs.secondary.IgfsSecondaryFileSystemPositionedReadable;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.hadoop.HadoopClassLoader;
+import org.apache.ignite.internal.processors.hadoop.HadoopCommonUtils;
 import org.apache.ignite.internal.processors.hadoop.HadoopPayloadAware;
 import org.apache.ignite.internal.processors.hadoop.delegate.HadoopDelegateUtils;
 import org.apache.ignite.internal.processors.hadoop.delegate.HadoopIgfsSecondaryFileSystemDelegate;
+import org.apache.ignite.internal.processors.igfs.IgfsKernalContextAware;
 import org.apache.ignite.internal.processors.igfs.IgfsSecondaryFileSystemV2;
 import org.apache.ignite.lang.IgniteOutClosure;
 import org.apache.ignite.lifecycle.LifecycleAware;
@@ -42,16 +46,19 @@ import java.util.concurrent.Callable;
  * <p>
  * Target {@code FileSystem}'s are created on per-user basis using passed {@link HadoopFileSystemFactory}.
  */
-public class IgniteHadoopIgfsSecondaryFileSystem implements IgfsSecondaryFileSystemV2, LifecycleAware,
-    HadoopPayloadAware {
+public class IgniteHadoopIgfsSecondaryFileSystem implements IgfsSecondaryFileSystemV2, IgfsKernalContextAware,
+    LifecycleAware, HadoopPayloadAware {
     /** The default user name. It is used if no user context is set. */
     private String dfltUsrName;
 
     /** Factory. */
     private HadoopFileSystemFactory factory;
 
+    /** Kernal context. */
+    private volatile GridKernalContext ctx;
+
     /** Target. */
-    volatile private HadoopIgfsSecondaryFileSystemDelegate target;
+    private volatile HadoopIgfsSecondaryFileSystemDelegate target;
 
     /**
      * Default constructor for Spring.
@@ -238,10 +245,24 @@ public class IgniteHadoopIgfsSecondaryFileSystem implements IgfsSecondaryFileSys
     }
 
     /** {@inheritDoc} */
+    @Override public void setKernalContext(GridKernalContext ctx) {
+        this.ctx = ctx;
+    }
+
+    /** {@inheritDoc} */
     @Override public void start() throws IgniteException {
-        target = HadoopDelegateUtils.secondaryFileSystemDelegate(this);
+        HadoopClassLoader ldr = ctx.hadoopHelper().commonClassLoader();
+
+        ClassLoader oldLdr = HadoopCommonUtils.setContextClassLoader(ldr);
+
+        try {
+            target = HadoopDelegateUtils.secondaryFileSystemDelegate(ldr, this);
 
-        target.start();
+            target.start();
+        }
+        finally {
+            HadoopCommonUtils.restoreContextClassLoader(oldLdr);
+        }
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/2b6c36eb/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopCommonUtils.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopCommonUtils.java
b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopCommonUtils.java
index 55c8a1b..2fed651 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopCommonUtils.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopCommonUtils.java
@@ -17,8 +17,7 @@
 
 package org.apache.ignite.internal.processors.hadoop;
 
-import org.apache.ignite.internal.processors.hadoop.HadoopFileBlock;
-import org.apache.ignite.internal.processors.hadoop.HadoopInputSplit;
+import org.jetbrains.annotations.Nullable;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -55,6 +54,33 @@ public class HadoopCommonUtils {
     }
 
     /**
+     * Set context class loader.
+     *
+     * @param newLdr New class loader.
+     * @return Old class loader.
+     */
+    @Nullable public static ClassLoader setContextClassLoader(@Nullable ClassLoader newLdr)
{
+        ClassLoader oldLdr = Thread.currentThread().getContextClassLoader();
+
+        if (newLdr != oldLdr)
+            Thread.currentThread().setContextClassLoader(newLdr);
+
+        return oldLdr;
+    }
+
+    /**
+     * Restore context class loader.
+     *
+     * @param oldLdr Original class loader.
+     */
+    public static void restoreContextClassLoader(@Nullable ClassLoader oldLdr) {
+        ClassLoader newLdr = Thread.currentThread().getContextClassLoader();
+
+        if (newLdr != oldLdr)
+            Thread.currentThread().setContextClassLoader(oldLdr);
+    }
+
+    /**
      * Split wrapper for sorting.
      */
     private static class SplitSortWrapper implements Comparable<SplitSortWrapper> {

http://git-wip-us.apache.org/repos/asf/ignite/blob/2b6c36eb/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/delegate/HadoopDelegateUtils.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/delegate/HadoopDelegateUtils.java
b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/delegate/HadoopDelegateUtils.java
index 3cd0135..8250a66 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/delegate/HadoopDelegateUtils.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/delegate/HadoopDelegateUtils.java
@@ -23,6 +23,8 @@ import org.apache.ignite.hadoop.fs.CachingHadoopFileSystemFactory;
 import org.apache.ignite.hadoop.fs.IgniteHadoopFileSystemCounterWriter;
 import org.apache.ignite.hadoop.fs.IgniteHadoopIgfsSecondaryFileSystem;
 import org.apache.ignite.hadoop.fs.KerberosHadoopFileSystemFactory;
+import org.apache.ignite.internal.processors.hadoop.HadoopClassLoader;
+import org.jetbrains.annotations.Nullable;
 
 import java.lang.reflect.Constructor;
 import java.util.HashMap;
@@ -63,12 +65,13 @@ public class HadoopDelegateUtils {
     /**
      * Create delegate for secondary file system.
      *
+     * @param ldr Hadoop class loader.
      * @param proxy Proxy.
      * @return Delegate.
      */
-    public static HadoopIgfsSecondaryFileSystemDelegate secondaryFileSystemDelegate(
+    public static HadoopIgfsSecondaryFileSystemDelegate secondaryFileSystemDelegate(HadoopClassLoader
ldr,
         IgniteHadoopIgfsSecondaryFileSystem proxy) {
-        return newInstance(SECONDARY_FILE_SYSTEM_CLS, proxy);
+        return newInstance(SECONDARY_FILE_SYSTEM_CLS, ldr, proxy);
     }
 
     /**
@@ -84,7 +87,7 @@ public class HadoopDelegateUtils {
         if (clsName == null)
             clsName = DFLT_FACTORY_CLS;
 
-        return newInstance(clsName, proxy);
+        return newInstance(clsName, null, proxy);
     }
 
     /**
@@ -95,20 +98,21 @@ public class HadoopDelegateUtils {
      */
     public static HadoopFileSystemCounterWriterDelegate counterWriterDelegate(
         IgniteHadoopFileSystemCounterWriter proxy) {
-        return newInstance(COUNTER_WRITER_DELEGATE_CLS, proxy);
+        return newInstance(COUNTER_WRITER_DELEGATE_CLS, null, proxy);
     }
 
     /**
      * Get new delegate instance.
      *
      * @param clsName Class name.
+     * @param ldr Optional class loader.
      * @param proxy Proxy.
      * @return Instance.
      */
     @SuppressWarnings("unchecked")
-    private static <T> T newInstance(String clsName, Object proxy) {
+    private static <T> T newInstance(String clsName, @Nullable ClassLoader ldr, Object
proxy) {
         try {
-            Class delegateCls = Class.forName(clsName);
+            Class delegateCls = ldr == null ? Class.forName(clsName) : Class.forName(clsName,
true, ldr);
 
             Constructor[] ctors = delegateCls.getConstructors();
 


Mime
View raw message