Skip to content

Commit

Permalink
Add support for Glue endpoint URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawel Palucha authored and sopel39 committed Apr 1, 2020
1 parent f922c85 commit 728be1a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Expand Up @@ -21,6 +21,7 @@
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.auth.InstanceProfileCredentialsProvider;
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider;
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.amazonaws.services.glue.AWSGlueAsync;
import com.amazonaws.services.glue.AWSGlueAsyncClientBuilder;
import com.amazonaws.services.glue.model.AlreadyExistsException;
Expand Down Expand Up @@ -112,6 +113,7 @@
import java.util.concurrent.Future;
import java.util.function.Function;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.Comparators.lexicographical;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
Expand Down Expand Up @@ -182,8 +184,13 @@ private static AWSGlueAsync createAsyncGlueClient(GlueHiveMetastoreConfig config
ClientConfiguration clientConfig = new ClientConfiguration().withMaxConnections(config.getMaxGlueConnections());
AWSGlueAsyncClientBuilder asyncGlueClientBuilder = AWSGlueAsyncClientBuilder.standard()
.withClientConfiguration(clientConfig);

if (config.getGlueRegion().isPresent()) {
if (config.getGlueEndpointUrl().isPresent()) {
checkArgument(config.getGlueRegion().isPresent(), "Glue region must be set when Glue endpoint URL is set");
asyncGlueClientBuilder.setEndpointConfiguration(new EndpointConfiguration(
config.getGlueEndpointUrl().get(),
config.getGlueRegion().get()));
}
else if (config.getGlueRegion().isPresent()) {
asyncGlueClientBuilder.setRegion(config.getGlueRegion().get());
}
else if (config.getPinGlueClientToCurrentRegion()) {
Expand Down
Expand Up @@ -25,6 +25,7 @@
public class GlueHiveMetastoreConfig
{
private Optional<String> glueRegion = Optional.empty();
private Optional<String> glueEndpointUrl = Optional.empty();
private boolean pinGlueClientToCurrentRegion;
private int maxGlueConnections = 5;
private Optional<String> defaultWarehouseDir = Optional.empty();
Expand All @@ -50,6 +51,19 @@ public GlueHiveMetastoreConfig setGlueRegion(String region)
return this;
}

public Optional<String> getGlueEndpointUrl()
{
return glueEndpointUrl;
}

@Config("hive.metastore.glue.endpoint-url")
@ConfigDescription("Glue API endpoint URL")
public GlueHiveMetastoreConfig setGlueEndpointUrl(String glueEndpointUrl)
{
this.glueEndpointUrl = Optional.ofNullable(glueEndpointUrl);
return this;
}

public boolean getPinGlueClientToCurrentRegion()
{
return pinGlueClientToCurrentRegion;
Expand Down
Expand Up @@ -29,6 +29,7 @@ public void testDefaults()
{
assertRecordedDefaults(recordDefaults(GlueHiveMetastoreConfig.class)
.setGlueRegion(null)
.setGlueEndpointUrl(null)
.setPinGlueClientToCurrentRegion(false)
.setMaxGlueConnections(5)
.setDefaultWarehouseDir(null)
Expand All @@ -47,6 +48,7 @@ public void testExplicitPropertyMapping()
{
Map<String, String> properties = new ImmutableMap.Builder<String, String>()
.put("hive.metastore.glue.region", "us-east-1")
.put("hive.metastore.glue.endpoint-url", "http://foo.bar")
.put("hive.metastore.glue.pin-client-to-current-region", "true")
.put("hive.metastore.glue.max-connections", "10")
.put("hive.metastore.glue.default-warehouse-dir", "/location")
Expand All @@ -62,6 +64,7 @@ public void testExplicitPropertyMapping()

GlueHiveMetastoreConfig expected = new GlueHiveMetastoreConfig()
.setGlueRegion("us-east-1")
.setGlueEndpointUrl("http://foo.bar")
.setPinGlueClientToCurrentRegion(true)
.setMaxGlueConnections(10)
.setDefaultWarehouseDir("/location")
Expand Down

0 comments on commit 728be1a

Please sign in to comment.