Skip to content

Commit

Permalink
Extract HiveAuthenticationConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Sep 23, 2019
1 parent 7946129 commit 44e6304
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 74 deletions.
56 changes: 0 additions & 56 deletions presto-hive/src/main/java/io/prestosql/plugin/hive/HiveConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -61,17 +60,17 @@ protected void setup(Binder binder)
kerberosImpersonatingHdfsAuthenticationModule());
}

private void bindAuthenticationModule(Predicate<HiveConfig> predicate, Module module)
private void bindAuthenticationModule(Predicate<HiveAuthenticationConfig> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> properties = new ImmutableMap.Builder<String, String>()
.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);
}
}

0 comments on commit 44e6304

Please sign in to comment.