Search in sources :

Example 1 with HiveS3Config

use of io.trino.plugin.hive.s3.HiveS3Config in project trino by trinodb.

the class TrinoS3ClientFactory method createS3Client.

private AmazonS3 createS3Client(Configuration config) {
    HiveS3Config defaults = new HiveS3Config();
    String userAgentPrefix = config.get(S3_USER_AGENT_PREFIX, defaults.getS3UserAgentPrefix());
    int maxErrorRetries = config.getInt(S3_MAX_ERROR_RETRIES, defaults.getS3MaxErrorRetries());
    boolean sslEnabled = config.getBoolean(S3_SSL_ENABLED, defaults.isS3SslEnabled());
    Duration connectTimeout = Duration.valueOf(config.get(S3_CONNECT_TIMEOUT, defaults.getS3ConnectTimeout().toString()));
    Duration socketTimeout = Duration.valueOf(config.get(S3_SOCKET_TIMEOUT, defaults.getS3SocketTimeout().toString()));
    int maxConnections = config.getInt(S3_SELECT_PUSHDOWN_MAX_CONNECTIONS, defaultMaxConnections);
    ClientConfiguration clientConfiguration = new ClientConfiguration().withMaxErrorRetry(maxErrorRetries).withProtocol(sslEnabled ? Protocol.HTTPS : Protocol.HTTP).withConnectionTimeout(toIntExact(connectTimeout.toMillis())).withSocketTimeout(toIntExact(socketTimeout.toMillis())).withMaxConnections(maxConnections).withUserAgentPrefix(userAgentPrefix).withUserAgentSuffix(enabled ? "Trino-select" : "Trino");
    AWSCredentialsProvider awsCredentialsProvider = getAwsCredentialsProvider(config);
    AmazonS3Builder<? extends AmazonS3Builder<?, ?>, ? extends AmazonS3> clientBuilder = AmazonS3Client.builder().withCredentials(awsCredentialsProvider).withClientConfiguration(clientConfiguration).withMetricsCollector(new TrinoS3FileSystemMetricCollector(TrinoS3FileSystem.getFileSystemStats())).enablePathStyleAccess();
    boolean regionOrEndpointSet = false;
    String endpoint = config.get(S3_ENDPOINT);
    boolean pinS3ClientToCurrentRegion = config.getBoolean(S3_PIN_CLIENT_TO_CURRENT_REGION, defaults.isPinS3ClientToCurrentRegion());
    verify(!pinS3ClientToCurrentRegion || endpoint == null, "Invalid configuration: either endpoint can be set or S3 client can be pinned to the current region");
    // use local region when running inside of EC2
    if (pinS3ClientToCurrentRegion) {
        clientBuilder.setRegion(getCurrentRegionFromEC2Metadata().getName());
        regionOrEndpointSet = true;
    }
    if (!isNullOrEmpty(endpoint)) {
        clientBuilder.withEndpointConfiguration(new EndpointConfiguration(endpoint, null));
        regionOrEndpointSet = true;
    }
    if (!regionOrEndpointSet) {
        clientBuilder.withRegion(US_EAST_1);
        clientBuilder.setForceGlobalBucketAccessEnabled(true);
    }
    return clientBuilder.build();
}
Also used : HiveS3Config(io.trino.plugin.hive.s3.HiveS3Config) TrinoS3FileSystemMetricCollector(io.trino.plugin.hive.s3.TrinoS3FileSystemMetricCollector) Duration(io.airlift.units.Duration) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) ClientConfiguration(com.amazonaws.ClientConfiguration) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 2 with HiveS3Config

use of io.trino.plugin.hive.s3.HiveS3Config in project trino by trinodb.

the class AbstractTestHiveFileSystemS3 method createHdfsConfiguration.

private HdfsConfiguration createHdfsConfiguration() {
    ConfigurationInitializer s3Config = new TrinoS3ConfigurationInitializer(new HiveS3Config().setS3AwsAccessKey(awsAccessKey).setS3AwsSecretKey(awsSecretKey));
    HdfsConfigurationInitializer initializer = new HdfsConfigurationInitializer(new HdfsConfig(), ImmutableSet.of(s3Config));
    return new HiveHdfsConfiguration(initializer, ImmutableSet.of());
}
Also used : HiveS3Config(io.trino.plugin.hive.s3.HiveS3Config) TrinoS3ConfigurationInitializer(io.trino.plugin.hive.s3.TrinoS3ConfigurationInitializer) TrinoS3ConfigurationInitializer(io.trino.plugin.hive.s3.TrinoS3ConfigurationInitializer)

Aggregations

HiveS3Config (io.trino.plugin.hive.s3.HiveS3Config)2 ClientConfiguration (com.amazonaws.ClientConfiguration)1 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 EndpointConfiguration (com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration)1 Duration (io.airlift.units.Duration)1 TrinoS3ConfigurationInitializer (io.trino.plugin.hive.s3.TrinoS3ConfigurationInitializer)1 TrinoS3FileSystemMetricCollector (io.trino.plugin.hive.s3.TrinoS3FileSystemMetricCollector)1