diff --git itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java index 4a4fbba..350cdf3 100644 --- itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java +++ itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java @@ -618,6 +618,19 @@ public void clearPostTestEffects() throws Exception { setup.postTest(conf); } + public void clearKeysCreatedInTests() { + if (hes == null) { + return; + } + try { + for (String keyAlias : hes.getKeys()) { + hes.deleteKey(keyAlias); + } + } catch (IOException e) { + LOG.error("Fail to clean the keys created in test due to the error", e); + } + } + /** * Clear out any side effects of running tests */ @@ -688,6 +701,7 @@ public void clearTestSideEffects() throws Exception { } clearTablesCreatedDuringTests(); + clearKeysCreatedInTests(); if (clusterType != MiniClusterType.encrypted) { // allocate and initialize a new conf since a test can @@ -697,6 +711,7 @@ public void clearTestSideEffects() throws Exception { // renew the metastore since the cluster type is unencrypted db = Hive.get(conf); // propagate new conf to meta store } + setup.preTest(conf); } @@ -709,6 +724,7 @@ public void cleanUp() throws Exception { } clearTablesCreatedDuringTests(); + clearKeysCreatedInTests(); SessionState.get().getConf().setBoolean("hive.test.shutdown.phase", true); diff --git shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java index 4fc24d1..c63f162 100644 --- shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java +++ shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java @@ -1048,9 +1048,7 @@ public void createEncryptionZone(Path path, String keyName) throws IOException { public void createKey(String keyName, int bitLength) throws IOException, NoSuchAlgorithmException { - if (keyProvider == null) { - throw new IOException("HDFS security key provider is not configured on your server."); - } + checkKeyProvider(); if (keyProvider.getMetadata(keyName) == null) { final KeyProvider.Options options = new Options(this.conf); @@ -1065,9 +1063,7 @@ public void createKey(String keyName, int bitLength) @Override public void deleteKey(String keyName) throws IOException { - if (keyProvider == null) { - throw new IOException("HDFS security key provider is not configured on your server."); - } + checkKeyProvider(); if (keyProvider.getMetadata(keyName) != null) { keyProvider.deleteKey(keyName); @@ -1077,6 +1073,18 @@ public void deleteKey(String keyName) throws IOException { } } + @Override + public List getKeys() throws IOException { + checkKeyProvider(); + return keyProvider.getKeys(); + } + + private void checkKeyProvider() throws IOException { + if (keyProvider == null) { + throw new IOException("HDFS security key provider is not configured on your server."); + } + } + /** * Compares two encryption key strengths. * diff --git shims/common/src/main/java/org/apache/hadoop/hive/shims/HadoopShims.java shims/common/src/main/java/org/apache/hadoop/hive/shims/HadoopShims.java index d84a10e..2dfec33 100644 --- shims/common/src/main/java/org/apache/hadoop/hive/shims/HadoopShims.java +++ shims/common/src/main/java/org/apache/hadoop/hive/shims/HadoopShims.java @@ -612,6 +612,9 @@ public void createKey(String keyName, int bitLength) @VisibleForTesting public void deleteKey(String keyName) throws IOException; + + @VisibleForTesting + public List getKeys() throws IOException; } /** @@ -649,7 +652,13 @@ public void createKey(String keyName, int bitLength) { @Override public void deleteKey(String keyName) throws IOException { /* not supported */ - }; + } + + @Override + public List getKeys() throws IOException{ + /* not supported */ + return null; + } } /**