use of com.amazonaws.ClientConfiguration in project cas by apereo.
the class DynamoDbTicketRegistryConfiguration method amazonDynamoDbClient.
@RefreshScope
@Bean
public AmazonDynamoDBClient amazonDynamoDbClient() {
try {
final DynamoDbTicketRegistryProperties dynamoDbProperties = casProperties.getTicket().getRegistry().getDynamoDb();
final ClientConfiguration cfg = new ClientConfiguration();
cfg.setConnectionTimeout(dynamoDbProperties.getConnectionTimeout());
cfg.setMaxConnections(dynamoDbProperties.getMaxConnections());
cfg.setRequestTimeout(dynamoDbProperties.getRequestTimeout());
cfg.setSocketTimeout(dynamoDbProperties.getSocketTimeout());
cfg.setUseGzip(dynamoDbProperties.isUseGzip());
cfg.setUseReaper(dynamoDbProperties.isUseReaper());
cfg.setUseThrottleRetries(dynamoDbProperties.isUseThrottleRetries());
cfg.setUseTcpKeepAlive(dynamoDbProperties.isUseTcpKeepAlive());
cfg.setProtocol(Protocol.valueOf(dynamoDbProperties.getProtocol().toUpperCase()));
cfg.setClientExecutionTimeout(dynamoDbProperties.getClientExecutionTimeout());
cfg.setCacheResponseMetadata(dynamoDbProperties.isCacheResponseMetadata());
if (StringUtils.isNotBlank(dynamoDbProperties.getLocalAddress())) {
cfg.setLocalAddress(InetAddress.getByName(dynamoDbProperties.getLocalAddress()));
}
AWSCredentials credentials = null;
if (dynamoDbProperties.getCredentialsPropertiesFile() != null) {
credentials = new PropertiesCredentials(dynamoDbProperties.getCredentialsPropertiesFile().getInputStream());
} else if (StringUtils.isNotBlank(dynamoDbProperties.getCredentialAccessKey()) && StringUtils.isNotBlank(dynamoDbProperties.getCredentialSecretKey())) {
credentials = new BasicAWSCredentials(dynamoDbProperties.getCredentialAccessKey(), dynamoDbProperties.getCredentialSecretKey());
}
final AmazonDynamoDBClient client;
if (credentials == null) {
client = new AmazonDynamoDBClient(cfg);
} else {
client = new AmazonDynamoDBClient(credentials, cfg);
}
if (StringUtils.isNotBlank(dynamoDbProperties.getEndpoint())) {
client.setEndpoint(dynamoDbProperties.getEndpoint());
}
if (StringUtils.isNotBlank(dynamoDbProperties.getRegion())) {
client.setRegion(Region.getRegion(Regions.valueOf(dynamoDbProperties.getRegion())));
}
if (StringUtils.isNotBlank(dynamoDbProperties.getRegionOverride())) {
client.setSignerRegionOverride(dynamoDbProperties.getRegionOverride());
}
if (StringUtils.isNotBlank(dynamoDbProperties.getServiceNameIntern())) {
client.setServiceNameIntern(dynamoDbProperties.getServiceNameIntern());
}
if (dynamoDbProperties.getTimeOffset() != 0) {
client.setTimeOffset(dynamoDbProperties.getTimeOffset());
}
return client;
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
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;
}
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));
}
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;
}
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));
}
Aggregations