Search in sources :

Example 1 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project elasticsearch by elastic.

the class AwsS3ServiceImplTests method launchAWSConfigurationTest.

protected void launchAWSConfigurationTest(Settings settings, Settings singleRepositorySettings, Protocol expectedProtocol, String expectedProxyHost, int expectedProxyPort, String expectedProxyUsername, String expectedProxyPassword, String expectedSigner, Integer expectedMaxRetries, boolean expectedUseThrottleRetries, int expectedReadTimeout) {
    Integer maxRetries = S3Repository.getValue(singleRepositorySettings, settings, S3Repository.Repository.MAX_RETRIES_SETTING, S3Repository.Repositories.MAX_RETRIES_SETTING);
    Boolean useThrottleRetries = S3Repository.getValue(singleRepositorySettings, settings, S3Repository.Repository.USE_THROTTLE_RETRIES_SETTING, S3Repository.Repositories.USE_THROTTLE_RETRIES_SETTING);
    ClientConfiguration configuration = InternalAwsS3Service.buildConfiguration(logger, singleRepositorySettings, settings, "default", maxRetries, null, useThrottleRetries);
    assertThat(configuration.getResponseMetadataCacheSize(), is(0));
    assertThat(configuration.getProtocol(), is(expectedProtocol));
    assertThat(configuration.getProxyHost(), is(expectedProxyHost));
    assertThat(configuration.getProxyPort(), is(expectedProxyPort));
    assertThat(configuration.getProxyUsername(), is(expectedProxyUsername));
    assertThat(configuration.getProxyPassword(), is(expectedProxyPassword));
    assertThat(configuration.getSignerOverride(), is(expectedSigner));
    assertThat(configuration.getMaxErrorRetry(), is(expectedMaxRetries));
    assertThat(configuration.useThrottledRetries(), is(expectedUseThrottleRetries));
    assertThat(configuration.getSocketTimeout(), is(expectedReadTimeout));
}
Also used : ClientConfiguration(com.amazonaws.ClientConfiguration)

Example 2 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project elasticsearch by elastic.

the class AwsEc2ServiceImpl method buildConfiguration.

protected static ClientConfiguration buildConfiguration(Logger logger, Settings settings) {
    ClientConfiguration clientConfiguration = new ClientConfiguration();
    // the response metadata cache is only there for diagnostics purposes,
    // but can force objects from every response to the old generation.
    clientConfiguration.setResponseMetadataCacheSize(0);
    clientConfiguration.setProtocol(CLOUD_EC2.PROTOCOL_SETTING.get(settings));
    if (PROXY_HOST_SETTING.exists(settings) || CLOUD_EC2.PROXY_HOST_SETTING.exists(settings)) {
        String proxyHost = CLOUD_EC2.PROXY_HOST_SETTING.get(settings);
        Integer proxyPort = CLOUD_EC2.PROXY_PORT_SETTING.get(settings);
        String proxyUsername = CLOUD_EC2.PROXY_USERNAME_SETTING.get(settings);
        String proxyPassword = CLOUD_EC2.PROXY_PASSWORD_SETTING.get(settings);
        clientConfiguration.withProxyHost(proxyHost).withProxyPort(proxyPort).withProxyUsername(proxyUsername).withProxyPassword(proxyPassword);
    }
    // #155: we might have 3rd party users using older EC2 API version
    String awsSigner = CLOUD_EC2.SIGNER_SETTING.get(settings);
    if (Strings.hasText(awsSigner)) {
        logger.debug("using AWS API signer [{}]", awsSigner);
        AwsSigner.configureSigner(awsSigner, clientConfiguration);
    }
    // Increase the number of retries in case of 5xx API responses
    final Random rand = Randomness.get();
    RetryPolicy retryPolicy = new RetryPolicy(RetryPolicy.RetryCondition.NO_RETRY_CONDITION, new RetryPolicy.BackoffStrategy() {

        @Override
        public long delayBeforeNextRetry(AmazonWebServiceRequest originalRequest, AmazonClientException exception, int retriesAttempted) {
            // with 10 retries the max delay time is 320s/320000ms (10 * 2^5 * 1 * 1000)
            logger.warn("EC2 API request failed, retry again. Reason was:", exception);
            return 1000L * (long) (10d * Math.pow(2, retriesAttempted / 2.0d) * (1.0d + rand.nextDouble()));
        }
    }, 10, false);
    clientConfiguration.setRetryPolicy(retryPolicy);
    clientConfiguration.setSocketTimeout((int) CLOUD_EC2.READ_TIMEOUT.get(settings).millis());
    return clientConfiguration;
}
Also used : Random(java.util.Random) AmazonClientException(com.amazonaws.AmazonClientException) RetryPolicy(com.amazonaws.retry.RetryPolicy) AmazonWebServiceRequest(com.amazonaws.AmazonWebServiceRequest) ClientConfiguration(com.amazonaws.ClientConfiguration)

Example 3 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project elasticsearch by elastic.

the class AwsEc2ServiceImplTests method launchAWSConfigurationTest.

protected void launchAWSConfigurationTest(Settings settings, Protocol expectedProtocol, String expectedProxyHost, int expectedProxyPort, String expectedProxyUsername, String expectedProxyPassword, String expectedSigner, int expectedReadTimeout) {
    ClientConfiguration configuration = AwsEc2ServiceImpl.buildConfiguration(logger, settings);
    assertThat(configuration.getResponseMetadataCacheSize(), is(0));
    assertThat(configuration.getProtocol(), is(expectedProtocol));
    assertThat(configuration.getProxyHost(), is(expectedProxyHost));
    assertThat(configuration.getProxyPort(), is(expectedProxyPort));
    assertThat(configuration.getProxyUsername(), is(expectedProxyUsername));
    assertThat(configuration.getProxyPassword(), is(expectedProxyPassword));
    assertThat(configuration.getSignerOverride(), is(expectedSigner));
    assertThat(configuration.getSocketTimeout(), is(expectedReadTimeout));
}
Also used : ClientConfiguration(com.amazonaws.ClientConfiguration)

Example 4 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project elasticsearch by elastic.

the class InternalAwsS3Service method buildConfiguration.

// pkg private for tests
static ClientConfiguration buildConfiguration(Logger logger, Settings repositorySettings, Settings settings, String clientName, Integer maxRetries, String endpoint, boolean useThrottleRetries) {
    ClientConfiguration clientConfiguration = new ClientConfiguration();
    // the response metadata cache is only there for diagnostics purposes,
    // but can force objects from every response to the old generation.
    clientConfiguration.setResponseMetadataCacheSize(0);
    Protocol protocol = getConfigValue(repositorySettings, settings, clientName, S3Repository.PROTOCOL_SETTING, S3Repository.Repository.PROTOCOL_SETTING, S3Repository.Repositories.PROTOCOL_SETTING);
    clientConfiguration.setProtocol(protocol);
    String proxyHost = getConfigValue(null, settings, clientName, S3Repository.PROXY_HOST_SETTING, null, CLOUD_S3.PROXY_HOST_SETTING);
    if (Strings.hasText(proxyHost)) {
        Integer proxyPort = getConfigValue(null, settings, clientName, S3Repository.PROXY_PORT_SETTING, null, CLOUD_S3.PROXY_PORT_SETTING);
        try (SecureString proxyUsername = getConfigValue(null, settings, clientName, S3Repository.PROXY_USERNAME_SETTING, null, CLOUD_S3.PROXY_USERNAME_SETTING);
            SecureString proxyPassword = getConfigValue(null, settings, clientName, S3Repository.PROXY_PASSWORD_SETTING, null, CLOUD_S3.PROXY_PASSWORD_SETTING)) {
            clientConfiguration.withProxyHost(proxyHost).withProxyPort(proxyPort).withProxyUsername(proxyUsername.toString()).withProxyPassword(proxyPassword.toString());
        }
    }
    if (maxRetries != null) {
        // If not explicitly set, default to 3 with exponential backoff policy
        clientConfiguration.setMaxErrorRetry(maxRetries);
    }
    clientConfiguration.setUseThrottleRetries(useThrottleRetries);
    // #155: we might have 3rd party users using older S3 API version
    String awsSigner = CLOUD_S3.SIGNER_SETTING.get(settings);
    if (Strings.hasText(awsSigner)) {
        logger.debug("using AWS API signer [{}]", awsSigner);
        AwsSigner.configureSigner(awsSigner, clientConfiguration, endpoint);
    }
    TimeValue readTimeout = getConfigValue(null, settings, clientName, S3Repository.READ_TIMEOUT_SETTING, null, CLOUD_S3.READ_TIMEOUT);
    clientConfiguration.setSocketTimeout((int) readTimeout.millis());
    return clientConfiguration;
}
Also used : SecureString(org.elasticsearch.common.settings.SecureString) Protocol(com.amazonaws.Protocol) ClientConfiguration(com.amazonaws.ClientConfiguration) SecureString(org.elasticsearch.common.settings.SecureString) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 5 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project hadoop by apache.

the class ITestS3AConfiguration method testDefaultUserAgent.

@Test
public void testDefaultUserAgent() throws Exception {
    conf = new Configuration();
    fs = S3ATestUtils.createTestFileSystem(conf);
    assertNotNull(fs);
    AmazonS3 s3 = fs.getAmazonS3Client();
    assertNotNull(s3);
    ClientConfiguration awsConf = getField(s3, ClientConfiguration.class, "clientConfiguration");
    assertEquals("Hadoop " + VersionInfo.getVersion(), awsConf.getUserAgentPrefix());
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) Configuration(org.apache.hadoop.conf.Configuration) ClientConfiguration(com.amazonaws.ClientConfiguration) ClientConfiguration(com.amazonaws.ClientConfiguration) Test(org.junit.Test)

Aggregations

ClientConfiguration (com.amazonaws.ClientConfiguration)132 Test (org.junit.Test)35 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)29 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)17 AWSCredentials (com.amazonaws.auth.AWSCredentials)14 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)13 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)13 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)10 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)8 ClientConfigurationFactory (com.amazonaws.ClientConfigurationFactory)7 EnvVars (hudson.EnvVars)7 File (java.io.File)7 URI (java.net.URI)7 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)6 Configuration (org.apache.hadoop.conf.Configuration)6 AmazonClientException (com.amazonaws.AmazonClientException)5 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)5 EndpointConfiguration (com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration)5 Properties (java.util.Properties)5 Test (org.testng.annotations.Test)5