Search in sources :

Example 1 with DefaultsMode

use of software.amazon.awssdk.awscore.defaultsmode.DefaultsMode in project aws-sdk-java-v2 by aws.

the class AwsDefaultClientBuilder method resolveDefaultsMode.

private DefaultsMode resolveDefaultsMode(SdkClientConfiguration config) {
    DefaultsMode defaultsMode = config.option(AwsClientOption.DEFAULTS_MODE) != null ? config.option(AwsClientOption.DEFAULTS_MODE) : DefaultsModeResolver.create().profileFile(() -> config.option(SdkClientOption.PROFILE_FILE)).profileName(config.option(SdkClientOption.PROFILE_NAME)).resolve();
    if (defaultsMode == DefaultsMode.AUTO) {
        defaultsMode = autoDefaultsModeDiscovery.discover(config.option(AwsClientOption.AWS_REGION));
        DefaultsMode finalDefaultsMode = defaultsMode;
        log.debug(() -> String.format("Resolved %s client's AUTO configuration mode to %s", serviceName(), finalDefaultsMode));
    }
    return defaultsMode;
}
Also used : DefaultsMode(software.amazon.awssdk.awscore.defaultsmode.DefaultsMode)

Example 2 with DefaultsMode

use of software.amazon.awssdk.awscore.defaultsmode.DefaultsMode in project aws-sdk-java-v2 by aws.

the class DefaultsModeTest method nonLegacyDefaultsMode_shouldApplySdkDefaultsAndHttpDefaults.

@Test
public void nonLegacyDefaultsMode_shouldApplySdkDefaultsAndHttpDefaults() {
    DefaultsMode targetMode = DefaultsMode.IN_REGION;
    TestClient client = testClientBuilder().region(Region.US_WEST_1).defaultsMode(targetMode).httpClientBuilder((SdkHttpClient.Builder) serviceDefaults -> {
        AttributeMap defaultHttpConfig = DefaultsModeConfiguration.defaultHttpConfig(targetMode);
        AttributeMap mergedDefaults = SERVICE_DEFAULTS.merge(defaultHttpConfig);
        assertThat(serviceDefaults).isEqualTo(mergedDefaults);
        return mock(SdkHttpClient.class);
    }).build();
    assertThat(client.clientConfiguration.option(DEFAULTS_MODE)).isEqualTo(targetMode);
    AttributeMap attributes = DefaultsModeConfiguration.defaultConfig(targetMode);
    assertThat(client.clientConfiguration.option(RETRY_POLICY).retryMode()).isEqualTo(attributes.get(DEFAULT_RETRY_MODE));
    assertThat(client.clientConfiguration.option(DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT)).isEqualTo("regional");
}
Also used : AttributeMap(software.amazon.awssdk.utils.AttributeMap) DefaultsMode(software.amazon.awssdk.awscore.defaultsmode.DefaultsMode) Test(org.junit.Test)

Example 3 with DefaultsMode

use of software.amazon.awssdk.awscore.defaultsmode.DefaultsMode in project aws-sdk-java-v2 by aws.

the class DefaultsModeTest method nonLegacyDefaultsModeAsyncClient_shouldApplySdkDefaultsAndHttpDefaults.

@Test
public void nonLegacyDefaultsModeAsyncClient_shouldApplySdkDefaultsAndHttpDefaults() {
    DefaultsMode targetMode = DefaultsMode.IN_REGION;
    TestAsyncClient client = testAsyncClientBuilder().region(Region.US_WEST_1).defaultsMode(targetMode).httpClientBuilder((SdkHttpClient.Builder) serviceDefaults -> {
        AttributeMap defaultHttpConfig = DefaultsModeConfiguration.defaultHttpConfig(targetMode);
        AttributeMap mergedDefaults = SERVICE_DEFAULTS.merge(defaultHttpConfig);
        assertThat(serviceDefaults).isEqualTo(mergedDefaults);
        return mock(SdkHttpClient.class);
    }).build();
    assertThat(client.clientConfiguration.option(DEFAULTS_MODE)).isEqualTo(targetMode);
    AttributeMap attributes = DefaultsModeConfiguration.defaultConfig(targetMode);
    assertThat(client.clientConfiguration.option(RETRY_POLICY).retryMode()).isEqualTo(attributes.get(DEFAULT_RETRY_MODE));
}
Also used : AttributeMap(software.amazon.awssdk.utils.AttributeMap) DefaultsMode(software.amazon.awssdk.awscore.defaultsmode.DefaultsMode) Test(org.junit.Test)

Example 4 with DefaultsMode

use of software.amazon.awssdk.awscore.defaultsmode.DefaultsMode in project aws-sdk-java-v2 by aws.

the class AwsDefaultClientBuilder method mergeSmartDefaults.

private SdkClientConfiguration mergeSmartDefaults(SdkClientConfiguration configuration) {
    DefaultsMode defaultsMode = resolveDefaultsMode(configuration);
    AttributeMap defaultConfig = DefaultsModeConfiguration.defaultConfig(defaultsMode);
    return configuration.toBuilder().option(DEFAULTS_MODE, defaultsMode).build().merge(c -> c.option(SdkClientOption.DEFAULT_RETRY_MODE, defaultConfig.get(SdkClientOption.DEFAULT_RETRY_MODE)).option(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT, defaultConfig.get(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT)));
}
Also used : AttributeMap(software.amazon.awssdk.utils.AttributeMap) DefaultsMode(software.amazon.awssdk.awscore.defaultsmode.DefaultsMode)

Example 5 with DefaultsMode

use of software.amazon.awssdk.awscore.defaultsmode.DefaultsMode in project aws-sdk-java-v2 by aws.

the class DefaultsModeTest method autoMode_shouldResolveDefaultsMode.

@Test
public void autoMode_shouldResolveDefaultsMode() {
    DefaultsMode expectedMode = DefaultsMode.IN_REGION;
    when(autoModeDiscovery.discover(any(Region.class))).thenReturn(expectedMode);
    TestClient client = testClientBuilder().region(Region.US_WEST_1).defaultsMode(DefaultsMode.AUTO).build();
    assertThat(client.clientConfiguration.option(DEFAULTS_MODE)).isEqualTo(expectedMode);
}
Also used : DefaultsMode(software.amazon.awssdk.awscore.defaultsmode.DefaultsMode) Region(software.amazon.awssdk.regions.Region) Test(org.junit.Test)

Aggregations

DefaultsMode (software.amazon.awssdk.awscore.defaultsmode.DefaultsMode)5 Test (org.junit.Test)3 AttributeMap (software.amazon.awssdk.utils.AttributeMap)3 Region (software.amazon.awssdk.regions.Region)1