Hadoop processor is always created w/ HadoopClassLoader.

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

Branch: refs/heads/ignite-3949
Commit: 99cb18bbfd4c17d5c220df5e9d9f3857283a1f9d
Parents: 8ae2097
Author: vozerov-gridgain <voze...@gridgain.com>
Authored: Wed Sep 21 14:57:57 2016 +0300
Committer: vozerov-gridgain <voze...@gridgain.com>
Committed: Wed Sep 21 14:57:57 2016 +0300

----------------------------------------------------------------------
 .../ignite/internal/IgniteComponentType.java    | 57 ++++++++++++++++++++
 .../apache/ignite/internal/IgniteKernal.java    | 25 +++++----
 .../processors/hadoop/HadoopHelper.java         |  5 ++
 .../processors/hadoop/HadoopNoopHelper.java     |  5 ++
 .../processors/hadoop/HadoopHelperImpl.java     |  5 ++
 5 files changed, 88 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/99cb18bb/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java
index c39e9c3..fa5240e 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java
@@ -199,6 +199,32 @@ public enum IgniteComponentType {
     /**
      * Creates component.
      *
+     * @param ctx Kernal context.
+     * @param ldr Class loader.
+     * @param mandatory If the component is mandatory.
+     * @return Created component.
+     * @throws IgniteCheckedException If failed.
+     */
+    public <T> T createIfInClassPath(GridKernalContext ctx, ClassLoader ldr, 
boolean mandatory)
+        throws IgniteCheckedException {
+        String cls = clsName;
+
+        try {
+            Class.forName(cls, true, ldr);
+        }
+        catch (ClassNotFoundException e) {
+            if (mandatory)
+                throw componentException(e);
+
+            cls = noOpClsName;
+        }
+
+        return create0(ctx, ldr, cls);
+    }
+
+    /**
+     * Creates component.
+     *
      * @param noOp No-op flag.
      * @return Created component.
      * @throws IgniteCheckedException If failed.
@@ -298,6 +324,37 @@ public enum IgniteComponentType {
     }
 
     /**
+     * Creates component instance.
+     *
+     * @param ctx Kernal context.
+     * @param ldr Class loader.
+     * @param clsName Component class name.
+     * @return Component instance.
+     * @throws IgniteCheckedException If failed.
+     */
+    @SuppressWarnings("unchecked")
+    private <T> T create0(@Nullable GridKernalContext ctx, ClassLoader ldr, 
String clsName)
+        throws IgniteCheckedException {
+        try {
+            Class<?> cls = Class.forName(clsName, true, ldr);
+
+            if (ctx == null) {
+                Constructor<?> ctor = cls.getConstructor();
+
+                return (T)ctor.newInstance();
+            }
+            else {
+                Constructor<?> ctor = 
cls.getConstructor(GridKernalContext.class);
+
+                return (T)ctor.newInstance(ctx);
+            }
+        }
+        catch (Throwable e) {
+            throw componentException(e);
+        }
+    }
+
+    /**
      * Creates message factory for the component.
      *
      * @return Message factory or {@code null} if none or the component is not 
in classpath.

http://git-wip-us.apache.org/repos/asf/ignite/blob/99cb18bb/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java 
b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index c909de5..ed2221d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -115,6 +115,7 @@ import 
org.apache.ignite.internal.processors.continuous.GridContinuousProcessor;
 import org.apache.ignite.internal.processors.datastreamer.DataStreamProcessor;
 import 
org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor;
 import org.apache.ignite.internal.processors.hadoop.Hadoop;
+import org.apache.ignite.internal.processors.hadoop.HadoopClassLoader;
 import org.apache.ignite.internal.processors.hadoop.HadoopProcessorAdapter;
 import org.apache.ignite.internal.processors.job.GridJobProcessor;
 import 
org.apache.ignite.internal.processors.jobmetrics.GridJobMetricsProcessor;
@@ -1142,7 +1143,9 @@ public class IgniteKernal implements IgniteEx, 
IgniteMXBean, Externalizable {
                 throw new IgniteCheckedException("Hadoop module cannot be used 
with peer class loading enabled " +
                     "(set IgniteConfiguration.peerClassLoadingEnabled to 
\"false\").");
 
-            HadoopProcessorAdapter res = 
IgniteComponentType.HADOOP.createIfInClassPath(ctx, true);
+            HadoopClassLoader ldr = ctx.hadoopHelper().commonClassLoader();
+
+            HadoopProcessorAdapter res = 
IgniteComponentType.HADOOP.createIfInClassPath(ctx, ldr, true);
 
             res.validateEnvironment();
 
@@ -1151,21 +1154,25 @@ public class IgniteKernal implements IgniteEx, 
IgniteMXBean, Externalizable {
         else {
             HadoopProcessorAdapter cmp = null;
 
-            if (IgniteComponentType.HADOOP.inClassPath() && 
cfg.isPeerClassLoadingEnabled()) {
+            if (!ctx.hadoopHelper().isNoOp() && 
cfg.isPeerClassLoadingEnabled()) {
                 U.warn(log, "Hadoop module is found in classpath, but will not 
be started because peer class " +
                     "loading is enabled (set 
IgniteConfiguration.peerClassLoadingEnabled to \"false\" if you want " +
                     "to use Hadoop module).");
             }
             else {
-                cmp = IgniteComponentType.HADOOP.createIfInClassPath(ctx, 
false);
+                if (!ctx.hadoopHelper().isNoOp()) {
+                    HadoopClassLoader ldr = 
ctx.hadoopHelper().commonClassLoader();
 
-                try {
-                    cmp.validateEnvironment();
-                }
-                catch (IgniteException | IgniteCheckedException e) {
-                    U.quietAndWarn(log, "Hadoop module will not start due to 
exception: " + e.getMessage());
+                    cmp = IgniteComponentType.HADOOP.createIfInClassPath(ctx, 
ldr, false);
 
-                    cmp = null;
+                    try {
+                        cmp.validateEnvironment();
+                    }
+                    catch (IgniteException | IgniteCheckedException e) {
+                        U.quietAndWarn(log, "Hadoop module will not start due 
to exception: " + e.getMessage());
+
+                        cmp = null;
+                    }
                 }
             }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/99cb18bb/modules/core/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopHelper.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopHelper.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopHelper.java
index 580c8aa..a8fee79 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopHelper.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopHelper.java
@@ -25,6 +25,11 @@ import org.jetbrains.annotations.Nullable;
  */
 public interface HadoopHelper {
     /**
+     * @return Whether this is no-op implementation.
+     */
+    public boolean isNoOp();
+
+    /**
      * Get common Hadoop class loader.
      *
      * @return Common Hadoop class loader.

http://git-wip-us.apache.org/repos/asf/ignite/blob/99cb18bb/modules/core/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopNoopHelper.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopNoopHelper.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopNoopHelper.java
index 814315b..d3348ca 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopNoopHelper.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopNoopHelper.java
@@ -38,6 +38,11 @@ public class HadoopNoopHelper implements HadoopHelper {
     }
 
     /** {@inheritDoc} */
+    @Override public boolean isNoOp() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
     @Override public HadoopClassLoader commonClassLoader() {
         throw unsupported();
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/99cb18bb/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopHelperImpl.java
----------------------------------------------------------------------
diff --git 
a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopHelperImpl.java
 
b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopHelperImpl.java
index e553dc5..71bb8a4 100644
--- 
a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopHelperImpl.java
+++ 
b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopHelperImpl.java
@@ -54,6 +54,11 @@ public class HadoopHelperImpl implements HadoopHelper {
     }
 
     /** {@inheritDoc} */
+    @Override public boolean isNoOp() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
     @Override public HadoopClassLoader commonClassLoader() {
         HadoopClassLoader res = ldr;
 

Reply via email to