You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by br...@apache.org on 2015/01/19 18:28:54 UTC

svn commit: r1653062 [6/6] - in /hive/trunk: common/src/java/org/apache/hadoop/hive/common/ common/src/java/org/apache/hadoop/hive/conf/ data/scripts/ hbase-handler/src/java/org/apache/hadoop/hive/hbase/ hcatalog/core/src/main/java/org/apache/hive/hcat...

Modified: hive/trunk/shims/common/src/main/java/org/apache/hadoop/hive/shims/HadoopShims.java
URL: http://svn.apache.org/viewvc/hive/trunk/shims/common/src/main/java/org/apache/hadoop/hive/shims/HadoopShims.java?rev=1653062&r1=1653061&r2=1653062&view=diff
==============================================================================
--- hive/trunk/shims/common/src/main/java/org/apache/hadoop/hive/shims/HadoopShims.java (original)
+++ hive/trunk/shims/common/src/main/java/org/apache/hadoop/hive/shims/HadoopShims.java Mon Jan 19 17:28:53 2015
@@ -23,12 +23,19 @@ import java.net.MalformedURLException;
 import java.net.URI;
 import java.nio.ByteBuffer;
 import java.security.AccessControlException;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivilegedExceptionAction;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
 
+import javax.security.auth.login.LoginException;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.BlockLocation;
 import org.apache.hadoop.fs.FSDataInputStream;
@@ -567,4 +574,131 @@ public interface HadoopShims {
     public String getShortName() throws IOException;
   }
 
+  /**
+   * Copies a source dir/file to a destination by orchestrating the copy between hdfs nodes.
+   * This distributed process is meant to copy huge files that could take some time if a single
+   * copy is done.
+   *
+   * @param src Path to the source file or directory to copy
+   * @param dst Path to the destination file or directory
+   * @param conf The hadoop configuration object
+   * @return True if it is successfull; False otherwise.
+   */
+  public boolean runDistCp(Path src, Path dst, Configuration conf) throws IOException;
+
+  /**
+   * This interface encapsulates methods used to get encryption information from
+   * HDFS paths.
+   */
+  public interface HdfsEncryptionShim {
+    /**
+     * Checks if a given HDFS path is encrypted.
+     *
+     * @param path Path to HDFS file system
+     * @return True if it is encrypted; False otherwise.
+     * @throws IOException If an error occurred attempting to get encryption information
+     */
+    public boolean isPathEncrypted(Path path) throws IOException;
+
+    /**
+     * Checks if two HDFS paths are on the same encrypted or unencrypted zone.
+     *
+     * @param path1 Path to HDFS file system
+     * @param path2 Path to HDFS file system
+     * @return True if both paths are in the same zone; False otherwise.
+     * @throws IOException If an error occurred attempting to get encryption information
+     */
+    public boolean arePathsOnSameEncryptionZone(Path path1, Path path2) throws IOException;
+
+    /**
+     * Compares two encrypted path strengths.
+     *
+     * @param path1 HDFS path to compare.
+     * @param path2 HDFS path to compare.
+     * @return 1 if path1 is stronger; 0 if paths are equals; -1 if path1 is weaker.
+     * @throws IOException If an error occurred attempting to get encryption/key metadata
+     */
+    public int comparePathKeyStrength(Path path1, Path path2) throws IOException;
+
+    /**
+     * create encryption zone by path and keyname
+     * @param path HDFS path to create encryption zone
+     * @param keyName keyname
+     * @throws IOException
+     */
+    @VisibleForTesting
+    public void createEncryptionZone(Path path, String keyName) throws IOException;
+
+    /**
+     * Creates an encryption key.
+     *
+     * @param keyName Name of the key
+     * @param bitLength Key encryption length in bits (128 or 256).
+     * @throws IOException If an error occurs while creating the encryption key
+     * @throws NoSuchAlgorithmException If cipher algorithm is invalid.
+     */
+    @VisibleForTesting
+    public void createKey(String keyName, int bitLength)
+      throws IOException, NoSuchAlgorithmException;
+
+    @VisibleForTesting
+    public void deleteKey(String keyName) throws IOException;
+
+    @VisibleForTesting
+    public List<String> getKeys() throws IOException;
+  }
+
+  /**
+   * This is a dummy class used when the hadoop version does not support hdfs encryption.
+   */
+  public static class NoopHdfsEncryptionShim implements HdfsEncryptionShim {
+    @Override
+    public boolean isPathEncrypted(Path path) throws IOException {
+    /* not supported */
+      return false;
+    }
+
+    @Override
+    public boolean arePathsOnSameEncryptionZone(Path path1, Path path2) throws IOException {
+    /* not supported */
+      return true;
+    }
+
+    @Override
+    public int comparePathKeyStrength(Path path1, Path path2) throws IOException {
+    /* not supported */
+      return 0;
+    }
+
+    @Override
+    public void createEncryptionZone(Path path, String keyName) {
+    /* not supported */
+    }
+
+    @Override
+    public void createKey(String keyName, int bitLength) {
+    /* not supported */
+    }
+
+    @Override
+    public void deleteKey(String keyName) throws IOException {
+    /* not supported */
+    }
+
+    @Override
+    public List<String> getKeys() throws IOException{
+    /* not supported */
+      return null;
+    }
+  }
+
+  /**
+   * Returns a new instance of the HdfsEncryption shim.
+   *
+   * @param fs A FileSystem object to HDFS
+   * @param conf A Configuration object
+   * @return A new instance of the HdfsEncryption shim.
+   * @throws IOException If an error occurred while creating the instance.
+   */
+  public HdfsEncryptionShim createHdfsEncryptionShim(FileSystem fs, Configuration conf) throws IOException;
 }