diff --git a/presto-hive/src/main/java/io/prestosql/plugin/hive/HiveConfig.java b/presto-hive/src/main/java/io/prestosql/plugin/hive/HiveConfig.java index 50f0d9086282..42799631d17c 100644 --- a/presto-hive/src/main/java/io/prestosql/plugin/hive/HiveConfig.java +++ b/presto-hive/src/main/java/io/prestosql/plugin/hive/HiveConfig.java @@ -120,9 +120,6 @@ public class HiveConfig private boolean rcfileWriterValidate; - private HiveMetastoreAuthenticationType hiveMetastoreAuthenticationType = HiveMetastoreAuthenticationType.NONE; - private HdfsAuthenticationType hdfsAuthenticationType = HdfsAuthenticationType.NONE; - private boolean hdfsImpersonationEnabled; private boolean hdfsWireEncryptionEnabled; private boolean skipDeletionForAlter; @@ -907,59 +904,6 @@ public HiveConfig setFileStatusCacheExpireAfterWrite(Duration fileStatusCacheExp return this; } - public enum HiveMetastoreAuthenticationType - { - NONE, - KERBEROS - } - - @NotNull - public HiveMetastoreAuthenticationType getHiveMetastoreAuthenticationType() - { - return hiveMetastoreAuthenticationType; - } - - @Config("hive.metastore.authentication.type") - @ConfigDescription("Hive Metastore authentication type") - public HiveConfig setHiveMetastoreAuthenticationType(HiveMetastoreAuthenticationType hiveMetastoreAuthenticationType) - { - this.hiveMetastoreAuthenticationType = hiveMetastoreAuthenticationType; - return this; - } - - public enum HdfsAuthenticationType - { - NONE, - KERBEROS, - } - - @NotNull - public HdfsAuthenticationType getHdfsAuthenticationType() - { - return hdfsAuthenticationType; - } - - @Config("hive.hdfs.authentication.type") - @ConfigDescription("HDFS authentication type") - public HiveConfig setHdfsAuthenticationType(HdfsAuthenticationType hdfsAuthenticationType) - { - this.hdfsAuthenticationType = hdfsAuthenticationType; - return this; - } - - public boolean isHdfsImpersonationEnabled() - { - return hdfsImpersonationEnabled; - } - - @Config("hive.hdfs.impersonation.enabled") - @ConfigDescription("Should Presto user be impersonated when communicating with HDFS") - public HiveConfig setHdfsImpersonationEnabled(boolean hdfsImpersonationEnabled) - { - this.hdfsImpersonationEnabled = hdfsImpersonationEnabled; - return this; - } - public boolean isHdfsWireEncryptionEnabled() { return hdfsWireEncryptionEnabled; diff --git a/presto-hive/src/main/java/io/prestosql/plugin/hive/authentication/HiveAuthenticationConfig.java b/presto-hive/src/main/java/io/prestosql/plugin/hive/authentication/HiveAuthenticationConfig.java new file mode 100644 index 000000000000..e89e3313b4b8 --- /dev/null +++ b/presto-hive/src/main/java/io/prestosql/plugin/hive/authentication/HiveAuthenticationConfig.java @@ -0,0 +1,79 @@ +/* + * Licensed 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 io.prestosql.plugin.hive.authentication; + +import io.airlift.configuration.Config; +import io.airlift.configuration.ConfigDescription; + +import javax.validation.constraints.NotNull; + +public class HiveAuthenticationConfig +{ + private HiveMetastoreAuthenticationType hiveMetastoreAuthenticationType = HiveMetastoreAuthenticationType.NONE; + private HdfsAuthenticationType hdfsAuthenticationType = HdfsAuthenticationType.NONE; + private boolean hdfsImpersonationEnabled; + + public enum HiveMetastoreAuthenticationType + { + NONE, + KERBEROS + } + + @NotNull + public HiveMetastoreAuthenticationType getHiveMetastoreAuthenticationType() + { + return hiveMetastoreAuthenticationType; + } + + @Config("hive.metastore.authentication.type") + @ConfigDescription("Hive Metastore authentication type") + public HiveAuthenticationConfig setHiveMetastoreAuthenticationType(HiveMetastoreAuthenticationType hiveMetastoreAuthenticationType) + { + this.hiveMetastoreAuthenticationType = hiveMetastoreAuthenticationType; + return this; + } + + public enum HdfsAuthenticationType + { + NONE, + KERBEROS, + } + + @NotNull + public HdfsAuthenticationType getHdfsAuthenticationType() + { + return hdfsAuthenticationType; + } + + @Config("hive.hdfs.authentication.type") + @ConfigDescription("HDFS authentication type") + public HiveAuthenticationConfig setHdfsAuthenticationType(HdfsAuthenticationType hdfsAuthenticationType) + { + this.hdfsAuthenticationType = hdfsAuthenticationType; + return this; + } + + public boolean isHdfsImpersonationEnabled() + { + return hdfsImpersonationEnabled; + } + + @Config("hive.hdfs.impersonation.enabled") + @ConfigDescription("Should Presto user be impersonated when communicating with HDFS") + public HiveAuthenticationConfig setHdfsImpersonationEnabled(boolean hdfsImpersonationEnabled) + { + this.hdfsImpersonationEnabled = hdfsImpersonationEnabled; + return this; + } +} diff --git a/presto-hive/src/main/java/io/prestosql/plugin/hive/authentication/HiveAuthenticationModule.java b/presto-hive/src/main/java/io/prestosql/plugin/hive/authentication/HiveAuthenticationModule.java index 6fd27cb75246..3a4d0f437e31 100644 --- a/presto-hive/src/main/java/io/prestosql/plugin/hive/authentication/HiveAuthenticationModule.java +++ b/presto-hive/src/main/java/io/prestosql/plugin/hive/authentication/HiveAuthenticationModule.java @@ -16,9 +16,8 @@ import com.google.inject.Binder; import com.google.inject.Module; import io.airlift.configuration.AbstractConfigurationAwareModule; -import io.prestosql.plugin.hive.HiveConfig; -import io.prestosql.plugin.hive.HiveConfig.HdfsAuthenticationType; -import io.prestosql.plugin.hive.HiveConfig.HiveMetastoreAuthenticationType; +import io.prestosql.plugin.hive.authentication.HiveAuthenticationConfig.HdfsAuthenticationType; +import io.prestosql.plugin.hive.authentication.HiveAuthenticationConfig.HiveMetastoreAuthenticationType; import java.util.function.Predicate; @@ -61,17 +60,17 @@ protected void setup(Binder binder) kerberosImpersonatingHdfsAuthenticationModule()); } - private void bindAuthenticationModule(Predicate predicate, Module module) + private void bindAuthenticationModule(Predicate predicate, Module module) { - install(installModuleIf(HiveConfig.class, predicate, module)); + install(installModuleIf(HiveAuthenticationConfig.class, predicate, module)); } - private static boolean noHdfsAuth(HiveConfig config) + private static boolean noHdfsAuth(HiveAuthenticationConfig config) { return config.getHdfsAuthenticationType() == HdfsAuthenticationType.NONE; } - private static boolean kerberosHdfsAuth(HiveConfig config) + private static boolean kerberosHdfsAuth(HiveAuthenticationConfig config) { return config.getHdfsAuthenticationType() == HdfsAuthenticationType.KERBEROS; } diff --git a/presto-hive/src/test/java/io/prestosql/plugin/hive/TestHiveConfig.java b/presto-hive/src/test/java/io/prestosql/plugin/hive/TestHiveConfig.java index 521d8a8a0413..6b5f46c10761 100644 --- a/presto-hive/src/test/java/io/prestosql/plugin/hive/TestHiveConfig.java +++ b/presto-hive/src/test/java/io/prestosql/plugin/hive/TestHiveConfig.java @@ -20,8 +20,6 @@ import io.airlift.units.DataSize.Unit; import io.airlift.units.Duration; import io.prestosql.orc.OrcWriteValidation.OrcWriteValidationMode; -import io.prestosql.plugin.hive.HiveConfig.HdfsAuthenticationType; -import io.prestosql.plugin.hive.HiveConfig.HiveMetastoreAuthenticationType; import org.testng.annotations.Test; import java.util.Map; @@ -92,9 +90,6 @@ public void testDefaults() .setOrcWriteLegacyVersion(false) .setOrcWriterValidationPercentage(0.0) .setOrcWriterValidationMode(OrcWriteValidationMode.BOTH) - .setHiveMetastoreAuthenticationType(HiveMetastoreAuthenticationType.NONE) - .setHdfsAuthenticationType(HdfsAuthenticationType.NONE) - .setHdfsImpersonationEnabled(false) .setSkipDeletionForAlter(false) .setSkipTargetCleanupOnRollback(false) .setBucketExecutionEnabled(true) @@ -175,9 +170,6 @@ public void testExplicitPropertyMappings() .put("hive.orc.writer.use-legacy-version-number", "true") .put("hive.orc.writer.validation-percentage", "0.16") .put("hive.orc.writer.validation-mode", "DETAILED") - .put("hive.metastore.authentication.type", "KERBEROS") - .put("hive.hdfs.authentication.type", "KERBEROS") - .put("hive.hdfs.impersonation.enabled", "true") .put("hive.skip-deletion-for-alter", "true") .put("hive.skip-target-cleanup-on-rollback", "true") .put("hive.bucket-execution", "false") @@ -256,9 +248,6 @@ public void testExplicitPropertyMappings() .setOrcWriteLegacyVersion(true) .setOrcWriterValidationPercentage(0.16) .setOrcWriterValidationMode(OrcWriteValidationMode.DETAILED) - .setHiveMetastoreAuthenticationType(HiveMetastoreAuthenticationType.KERBEROS) - .setHdfsAuthenticationType(HdfsAuthenticationType.KERBEROS) - .setHdfsImpersonationEnabled(true) .setSkipDeletionForAlter(true) .setSkipTargetCleanupOnRollback(true) .setBucketExecutionEnabled(false) diff --git a/presto-hive/src/test/java/io/prestosql/plugin/hive/authentication/TestHiveAuthenticationConfig.java b/presto-hive/src/test/java/io/prestosql/plugin/hive/authentication/TestHiveAuthenticationConfig.java new file mode 100644 index 000000000000..4b7e912e0fb9 --- /dev/null +++ b/presto-hive/src/test/java/io/prestosql/plugin/hive/authentication/TestHiveAuthenticationConfig.java @@ -0,0 +1,54 @@ +/* + * Licensed 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 io.prestosql.plugin.hive.authentication; + +import com.google.common.collect.ImmutableMap; +import io.prestosql.plugin.hive.authentication.HiveAuthenticationConfig.HdfsAuthenticationType; +import io.prestosql.plugin.hive.authentication.HiveAuthenticationConfig.HiveMetastoreAuthenticationType; +import org.testng.annotations.Test; + +import java.util.Map; + +import static io.airlift.configuration.testing.ConfigAssertions.assertFullMapping; +import static io.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults; +import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults; + +public class TestHiveAuthenticationConfig +{ + @Test + public void testDefaults() + { + assertRecordedDefaults(recordDefaults(HiveAuthenticationConfig.class) + .setHiveMetastoreAuthenticationType(HiveMetastoreAuthenticationType.NONE) + .setHdfsAuthenticationType(HdfsAuthenticationType.NONE) + .setHdfsImpersonationEnabled(false)); + } + + @Test + public void testExplicitPropertyMappings() + { + Map properties = new ImmutableMap.Builder() + .put("hive.metastore.authentication.type", "KERBEROS") + .put("hive.hdfs.authentication.type", "KERBEROS") + .put("hive.hdfs.impersonation.enabled", "true") + .build(); + + HiveAuthenticationConfig expected = new HiveAuthenticationConfig() + .setHiveMetastoreAuthenticationType(HiveMetastoreAuthenticationType.KERBEROS) + .setHdfsAuthenticationType(HdfsAuthenticationType.KERBEROS) + .setHdfsImpersonationEnabled(true); + + assertFullMapping(properties, expected); + } +}