Search in sources :

Example 1 with AWSGlueAsyncClientBuilder

use of com.amazonaws.services.glue.AWSGlueAsyncClientBuilder in project presto by prestodb.

the class GlueHiveMetastore method createAsyncGlueClient.

private static AWSGlueAsync createAsyncGlueClient(GlueHiveMetastoreConfig config, RequestMetricCollector metricsCollector) {
    ClientConfiguration clientConfig = new ClientConfiguration().withMaxConnections(config.getMaxGlueConnections()).withMaxErrorRetry(config.getMaxGlueErrorRetries());
    AWSGlueAsyncClientBuilder asyncGlueClientBuilder = AWSGlueAsyncClientBuilder.standard().withMetricsCollector(metricsCollector).withClientConfiguration(clientConfig);
    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()) {
        Region currentRegion = Regions.getCurrentRegion();
        if (currentRegion != null) {
            asyncGlueClientBuilder.setRegion(currentRegion.getName());
        }
    }
    if (config.getAwsAccessKey().isPresent() && config.getAwsSecretKey().isPresent()) {
        AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(new BasicAWSCredentials(config.getAwsAccessKey().get(), config.getAwsSecretKey().get()));
        asyncGlueClientBuilder.setCredentials(credentialsProvider);
    } else if (config.getIamRole().isPresent()) {
        AWSCredentialsProvider credentialsProvider = new STSAssumeRoleSessionCredentialsProvider.Builder(config.getIamRole().get(), "roleSessionName").build();
        asyncGlueClientBuilder.setCredentials(credentialsProvider);
    }
    return asyncGlueClientBuilder.build();
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AWSGlueAsyncClientBuilder(com.amazonaws.services.glue.AWSGlueAsyncClientBuilder) AWSGlueAsyncClientBuilder(com.amazonaws.services.glue.AWSGlueAsyncClientBuilder) Region(com.amazonaws.regions.Region) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) ClientConfiguration(com.amazonaws.ClientConfiguration) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 2 with AWSGlueAsyncClientBuilder

use of com.amazonaws.services.glue.AWSGlueAsyncClientBuilder in project alluxio by Alluxio.

the class GlueDatabase method createAsyncGlueClient.

/**
 * This method allows user to test udb glue client with remote glue server.
 *
 * @param config udbconfiguration
 * @return glue async client
 */
protected static AWSGlueAsync createAsyncGlueClient(UdbConfiguration config) {
    ClientConfiguration clientConfig = new ClientConfiguration().withMaxConnections(config.getInt(Property.MAX_GLUE_CONNECTION));
    if (!config.get(Property.AWS_PROXY_HOST).isEmpty()) {
        clientConfig.withProxyProtocol(getProtocol(config.get(Property.AWS_PROXY_PROTOCOL))).withProxyHost(config.get(Property.AWS_PROXY_HOST)).withProxyPort(config.getInt(Property.AWS_PROXY_PORT)).withProxyUsername(config.get(Property.AWS_PROXY_USER_NAME)).withProxyPassword(config.get(Property.AWS_PROXY_PASSWORD));
    }
    AWSGlueAsyncClientBuilder asyncClientBuilder = AWSGlueAsyncClientBuilder.standard().withClientConfiguration(clientConfig);
    if (!config.get(Property.GLUE_REGION).isEmpty()) {
        LOG.info("Set Glue region: {}.", config.get(Property.GLUE_REGION));
        asyncClientBuilder.setRegion(config.get(Property.GLUE_REGION));
    } else {
        LOG.warn("GlueDatabase: Please setup the AWS region.");
    }
    asyncClientBuilder.setCredentials(getAWSCredentialsProvider(config));
    return asyncClientBuilder.build();
}
Also used : AWSGlueAsyncClientBuilder(com.amazonaws.services.glue.AWSGlueAsyncClientBuilder) ClientConfiguration(com.amazonaws.ClientConfiguration)

Aggregations

ClientConfiguration (com.amazonaws.ClientConfiguration)2 AWSGlueAsyncClientBuilder (com.amazonaws.services.glue.AWSGlueAsyncClientBuilder)2 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 EndpointConfiguration (com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration)1 Region (com.amazonaws.regions.Region)1