You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/07/01 12:11:00 UTC

[17/27] ignite git commit: 3185: corrected error messages.

3185: corrected error messages.


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

Branch: refs/heads/ignite-3185
Commit: 6ff658aae7d2f4eb54f7dd6c4b71ea72f80c43d6
Parents: e575bf5
Author: iveselovskiy <iv...@gridgain.com>
Authored: Mon Jun 27 16:58:54 2016 +0300
Committer: iveselovskiy <iv...@gridgain.com>
Committed: Mon Jun 27 16:58:54 2016 +0300

----------------------------------------------------------------------
 .../processors/hadoop/HadoopClasspathUtils.java | 65 ++++++++++++++++----
 .../processors/hadoop/HadoopLocations.java      | 20 ++----
 .../processors/hadoop/HadoopProcessor.java      |  2 +-
 3 files changed, 59 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6ff658aa/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopClasspathUtils.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopClasspathUtils.java b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopClasspathUtils.java
index 598c1c3..5eb5c47 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopClasspathUtils.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopClasspathUtils.java
@@ -83,7 +83,7 @@ public class HadoopClasspathUtils {
     private static String hadoopHome() {
         String prefix = systemOrEnv("HADOOP_PREFIX", null);
 
-        return systemOrEnv("HADOOP_HOME", prefix);
+        return systemOrEnv(HadoopVariable.HADOOP_HOME.toString(), prefix);
     }
 
     /**
@@ -94,9 +94,9 @@ public class HadoopClasspathUtils {
     private static HadoopLocations getEnvHadoopLocations() {
         return new HadoopLocations(
             hadoopHome(),
-            systemOrEnv("HADOOP_COMMON_HOME", null),
-            systemOrEnv("HADOOP_HDFS_HOME", null),
-            systemOrEnv("HADOOP_MAPRED_HOME", null)
+            systemOrEnv(HadoopVariable.HADOOP_COMMON_HOME.toString(), null),
+            systemOrEnv(HadoopVariable.HADOOP_HDFS_HOME.toString(), null),
+            systemOrEnv(HadoopVariable.HADOOP_MAPRED_HOME.toString(), null)
         );
     }
 
@@ -116,8 +116,8 @@ public class HadoopClasspathUtils {
     private static final HadoopLocations HDP_HADOOP_LOCATIONS = new HadoopLocations(
         "/usr/hdp/current/hadoop-client",
         "/usr/hdp/current/hadoop-client",
-        "/usr/hdp/current/hadoop-hdfs-client/",
-        "/usr/hdp/current/hadoop-mapreduce-client/");
+        "/usr/hdp/current/hadoop-hdfs-client",
+        "/usr/hdp/current/hadoop-mapreduce-client");
 
     /**
      * HDP locations relative to an arbitrary Hadoop home.
@@ -127,8 +127,8 @@ public class HadoopClasspathUtils {
      */
     private static HadoopLocations getHdpLocationsRelative(String hadoopHome) {
         return new HadoopLocations(hadoopHome, hadoopHome,
-            hadoopHome + "/../hadoop-hdfs-client/",
-            hadoopHome + "/../hadoop-mapreduce-client/");
+            hadoopHome + "/../hadoop-hdfs-client",
+            hadoopHome + "/../hadoop-mapreduce-client");
     }
     
     /**
@@ -136,7 +136,7 @@ public class HadoopClasspathUtils {
      *
      * @return The locations as determined from the environment.
      */
-    private static HadoopLocations getHadoopLocations() throws IOException {
+    static HadoopLocations getHadoopLocations() throws IOException {
         // 1. Get Hadoop locations from the environment:
         HadoopLocations loc = getEnvHadoopLocations();
 
@@ -148,8 +148,7 @@ public class HadoopClasspathUtils {
         if (hadoopHome != null) {
             // If home is defined, it must exist:
             if (!directoryExists(hadoopHome))
-                throw new IOException("HADOOP_HOME location is not an existing readable directory. [dir="
-                    + hadoopHome + ']');
+                throw ioeNotFound(HadoopVariable.HADOOP_HOME.toString(), hadoopHome);
 
             // 2. Try Apache Hadoop locations defined relative to HADOOP_HOME:
             loc = getApacheHadoopLocations(hadoopHome);
@@ -160,11 +159,34 @@ public class HadoopClasspathUtils {
             // 3. Try HDP Hadoop locations defined relative to HADOOP_HOME:
             loc = getHdpLocationsRelative(hadoopHome);
 
-            return loc.existsOrException();
+            if (loc.exists())
+                return loc;
+
+            throw new IOException("Hadoop installation locations not found based on defined "
+                + HadoopVariable.HADOOP_HOME.toString() + " value. [" + HadoopVariable.HADOOP_HOME.toString()
+                + "=" + hadoopHome + ']');
         }
 
         // 4. Try absolute HDP (Hortonworks) location:
-        return HDP_HADOOP_LOCATIONS.existsOrException();
+        if (HDP_HADOOP_LOCATIONS.exists())
+            return HDP_HADOOP_LOCATIONS;
+
+        throw new IOException("Hadoop installation locations cannot be found. Please define environment variables "
+            + HadoopVariable.HADOOP_COMMON_HOME.toString() + ", "
+            + HadoopVariable.HADOOP_HDFS_HOME.toString() + ", "
+            + HadoopVariable.HADOOP_MAPRED_HOME.toString() + ", or "
+            + HadoopVariable.HADOOP_HOME.toString() + ".");
+    }
+
+    /**
+     * Convenience method to construct Exception.
+     *
+     * @param var The variable name.
+     * @param dir The dir.
+     * @return The Exception.
+     */
+    static IOException ioeNotFound(String var, String dir) {
+        return new IOException(var + " location is not an existing readable directory. [" + var + "=" + dir + ']');
     }
 
     /**
@@ -271,4 +293,21 @@ public class HadoopClasspathUtils {
             return filter != null;
         }
     }
+
+    /**
+     * Enumeration of commonly used Hadoop environment variables.
+     */
+    public enum HadoopVariable {
+        /** Variable HADOOP_HOME. */
+        HADOOP_HOME,
+
+        /** Variable HADOOP_COMMON_HOME. */
+        HADOOP_COMMON_HOME,
+
+        /** Variable HADOOP_HDFS_HOME. */
+        HADOOP_HDFS_HOME,
+
+        /** Variable HADOOP_MAPRED_HOME. */
+        HADOOP_MAPRED_HOME,
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/6ff658aa/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopLocations.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopLocations.java b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopLocations.java
index 597a8dc..9be42a5 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopLocations.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopLocations.java
@@ -105,25 +105,17 @@ public class HadoopLocations {
      */
     public HadoopLocations existsOrException() throws IOException {
         if (!HadoopClasspathUtils.directoryExists(commonHome))
-            throw ioe("HADOOP_COMMON_HOME");
+            throw HadoopClasspathUtils.ioeNotFound(HadoopClasspathUtils.HadoopVariable.HADOOP_COMMON_HOME.toString(),
+                commonHome);
 
         if (!HadoopClasspathUtils.directoryExists(hdfsHome))
-            throw ioe("HADOOP_HDFS_HOME");
+            throw HadoopClasspathUtils.ioeNotFound(HadoopClasspathUtils.HadoopVariable.HADOOP_HDFS_HOME.toString(),
+                hdfsHome);
 
         if (!HadoopClasspathUtils.directoryExists(mapredHome))
-            throw ioe("HADOOP_MAPRED_HOME");
+            throw HadoopClasspathUtils.ioeNotFound(HadoopClasspathUtils.HadoopVariable.HADOOP_MAPRED_HOME.toString(),
+                mapredHome);
 
         return this;
     }
-
-    /**
-     * Constructs the exception.
-     *
-     * @param var The 1st variable name to mention in the exception text.
-     * @return The exception.
-     */
-    private IOException ioe(String var) {
-        return new IOException("Failed to resolve Hadoop installation location. " + var +
-            " or HADOOP_HOME environment variable should be set.");
-    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/6ff658aa/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopProcessor.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopProcessor.java b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopProcessor.java
index c45953e..e84c23c 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopProcessor.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopProcessor.java
@@ -73,7 +73,7 @@ public class HadoopProcessor extends HadoopProcessorAdapter {
         validate(cfg);
 
         try {
-            HadoopLocations loc = HadoopClasspathUtils.hadoopLocations();
+            HadoopLocations loc = HadoopClasspathUtils.getHadoopLocations();
 
             if (loc.home() != null)
                 U.quietAndInfo(log, "HADOOP_HOME is set to " + loc.home());