List of usage examples for com.amazonaws ClientConfiguration ClientConfiguration
public ClientConfiguration()
From source file:com.netflix.edda.AwsClientFactory.java
License:Apache License
private static ClientConfiguration clientConfig(AwsConfiguration config) { return new ClientConfiguration().withConnectionTimeout((int) config.connectionTimeout().getMillis()) .withMaxConnections(config.maxConnections()).withMaxErrorRetry(config.maxErrorRetry()) .withSocketTimeout((int) config.socketTimeout().getMillis()) .withRetryPolicy(new RetryPolicy(new RetryPolicy.RetryCondition() { private final int maxRetries = config.maxErrorRetry(); @Override/*ww w .j a v a2s . com*/ public boolean shouldRetry(AmazonWebServiceRequest r, AmazonClientException e, int retriesAttempted) { if (e instanceof AmazonServiceException) { int code = ((AmazonServiceException) e).getStatusCode(); if (!(code % 100 == 5 || code == 400 || code == 403 || code == 429)) return false; } return retriesAttempted < maxRetries; } }, new RetryPolicy.BackoffStrategy() { @Override public long delayBeforeNextRetry(AmazonWebServiceRequest r, AmazonClientException e, int retriesAttempted) { return retriesAttempted * 1000L; } }, config.maxErrorRetry(), true)); }
From source file:com.netflix.eureka.aws.AwsAsgUtil.java
License:Apache License
private AutoScalingGroup retrieveAutoScalingGroupCrossAccount(String asgAccount, String asgName) { logger.debug("Getting cross account ASG for asgName: " + asgName + ", asgAccount: " + asgAccount); Credentials credentials = stsCredentials.get(asgAccount); if (credentials == null || credentials.getExpiration().getTime() < System.currentTimeMillis() + 1000) { stsCredentials.put(asgAccount, initializeStsSession(asgAccount)); credentials = stsCredentials.get(asgAccount); }//from w ww . j a v a2 s.co m ClientConfiguration clientConfiguration = new ClientConfiguration() .withConnectionTimeout(serverConfig.getASGQueryTimeoutMs()); AmazonAutoScaling autoScalingClient = new AmazonAutoScalingClient( new BasicSessionCredentials(credentials.getAccessKeyId(), credentials.getSecretAccessKey(), credentials.getSessionToken()), clientConfiguration); String region = clientConfig.getRegion(); if (!region.equals("us-east-1")) { autoScalingClient.setEndpoint("autoscaling." + region + ".amazonaws.com"); } DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest() .withAutoScalingGroupNames(asgName); DescribeAutoScalingGroupsResult result = autoScalingClient.describeAutoScalingGroups(request); List<AutoScalingGroup> asgs = result.getAutoScalingGroups(); if (asgs.isEmpty()) { return null; } else { return asgs.get(0); } }
From source file:com.netflix.eureka.aws.AwsAsgUtil.java
License:Apache License
private AmazonAutoScaling getAmazonAutoScalingClient() { String aWSAccessId = serverConfig.getAWSAccessId(); String aWSSecretKey = serverConfig.getAWSSecretKey(); ClientConfiguration clientConfiguration = new ClientConfiguration() .withConnectionTimeout(serverConfig.getASGQueryTimeoutMs()); if (null != aWSAccessId && !"".equals(aWSAccessId) && null != aWSSecretKey && !"".equals(aWSSecretKey)) { return new AmazonAutoScalingClient(new BasicAWSCredentials(aWSAccessId, aWSSecretKey), clientConfiguration);//from w w w. j a va2 s. com } else { return new AmazonAutoScalingClient(new InstanceProfileCredentialsProvider(), clientConfiguration); } }
From source file:com.netflix.eureka.util.AwsAsgUtil.java
License:Apache License
private AutoScalingGroup retrieveAutoScalingGroupCrossAccount(String asgAccount, String asgName) { logger.debug("Getting cross account ASG for asgName: " + asgName + ", asgAccount: " + asgAccount); Credentials credentials = stsCredentials.get(asgAccount); if (credentials == null || credentials.getExpiration().getTime() < System.currentTimeMillis() + 1000) { stsCredentials.put(asgAccount, initializeStsSession(asgAccount)); credentials = stsCredentials.get(asgAccount); }//from w w w . j ava 2 s . c o m ClientConfiguration clientConfiguration = new ClientConfiguration() .withConnectionTimeout(eurekaConfig.getASGQueryTimeoutMs()); AmazonAutoScaling autoScalingClient = new AmazonAutoScalingClient( new BasicSessionCredentials(credentials.getAccessKeyId(), credentials.getSecretAccessKey(), credentials.getSessionToken()), clientConfiguration); String region = DiscoveryManager.getInstance().getEurekaClientConfig().getRegion(); if (!region.equals("us-east-1")) { autoScalingClient.setEndpoint("autoscaling." + region + ".amazonaws.com"); } DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest() .withAutoScalingGroupNames(asgName); DescribeAutoScalingGroupsResult result = autoScalingClient.describeAutoScalingGroups(request); List<AutoScalingGroup> asgs = result.getAutoScalingGroups(); if (asgs.isEmpty()) { return null; } else { return asgs.get(0); } }
From source file:com.netflix.eureka.util.AwsAsgUtil.java
License:Apache License
private static AmazonAutoScaling getAmazonAutoScalingClient() { String aWSAccessId = eurekaConfig.getAWSAccessId(); String aWSSecretKey = eurekaConfig.getAWSSecretKey(); ClientConfiguration clientConfiguration = new ClientConfiguration() .withConnectionTimeout(eurekaConfig.getASGQueryTimeoutMs()); if (null != aWSAccessId && !"".equals(aWSAccessId) && null != aWSSecretKey && !"".equals(aWSSecretKey)) { return new AmazonAutoScalingClient(new BasicAWSCredentials(aWSAccessId, aWSSecretKey), clientConfiguration);/*from w w w . ja v a 2 s .c o m*/ } else { return new AmazonAutoScalingClient(new InstanceProfileCredentialsProvider(), clientConfiguration); } }
From source file:com.netflix.exhibitor.core.s3.PropertyBasedS3ClientConfig.java
License:Apache License
@Override public ClientConfiguration getAWSClientConfig() { ClientConfiguration awsClientConfig = new ClientConfiguration(); awsClientConfig.setProxyHost(proxyHost); awsClientConfig.setProxyPort(proxyPort); if (proxyUsername != null) { awsClientConfig.setProxyUsername(proxyUsername); }/*from www .j ava 2 s . co m*/ if (proxyPassword != null) { awsClientConfig.setProxyPassword(proxyPassword); } return awsClientConfig; }
From source file:com.netflix.genie.web.configs.aws.AwsS3Config.java
License:Apache License
/** * A bean providing a client to work with S3. * * @param noOfS3Retries No. of S3 request retries * @param awsCredentialsProvider A credentials provider used to instantiate the client. * @return An amazon s3 client object// w ww . j av a 2 s .com */ @Bean @ConditionalOnBean(AWSCredentialsProvider.class) public AmazonS3Client genieS3Client(@Value("${genie.retry.s3.noOfRetries:5}") final int noOfS3Retries, final AWSCredentialsProvider awsCredentialsProvider) { final ClientConfiguration clientConfiguration = new ClientConfiguration() .withRetryPolicy(PredefinedRetryPolicies.getDefaultRetryPolicyWithCustomMaxRetries(noOfS3Retries)); return new AmazonS3Client(awsCredentialsProvider, clientConfiguration); }
From source file:com.netflix.genie.web.configs.aws.GenieAwsS3AutoConfiguration.java
License:Apache License
/** * Default AWS client configuration that sets the number of retries provided by the user. * * @param retryProperties The properties related to retry configuration in Genie * @return The client configuration to use for all built AWS clients */// w ww . java 2s. co m @Bean @ConditionalOnMissingBean(name = "genieAwsClientConfiguration", value = ClientConfiguration.class) public ClientConfiguration genieAwsClientConfiguration(final RetryProperties retryProperties) { return new ClientConfiguration().withRetryPolicy(PredefinedRetryPolicies .getDefaultRetryPolicyWithCustomMaxRetries(retryProperties.getS3().getNoOfRetries())); }
From source file:com.netflix.ice.common.AwsUtils.java
License:Apache License
/** * This method must be called before all methods can be used. * @param credentialsProvider/*w ww . j a v a2 s . c o m*/ */ public static void init(AWSCredentialsProvider credentialsProvider) { awsCredentialsProvider = credentialsProvider; clientConfig = new ClientConfiguration(); String proxyHost = System.getProperty("https.proxyHost"); String proxyPort = System.getProperty("https.proxyPort"); if (proxyHost != null && proxyPort != null) { clientConfig.setProxyHost(proxyHost); clientConfig.setProxyPort(Integer.parseInt(proxyPort)); } s3Client = new AmazonS3Client(awsCredentialsProvider, clientConfig); securityClient = new AWSSecurityTokenServiceClient(awsCredentialsProvider, clientConfig); if (System.getProperty("EC2_REGION") != null && !"us-east-1".equals(System.getProperty("EC2_REGION"))) { if ("global".equals(System.getProperty("EC2_REGION"))) { s3Client.setEndpoint("s3.amazonaws.com"); } else { s3Client.setEndpoint("s3-" + System.getProperty("EC2_REGION") + ".amazonaws.com"); } } }
From source file:com.netflix.iep.aws.AwsClientFactory.java
License:Apache License
ClientConfiguration createClientConfig(String name) { final Config cfg = getConfig(name, "client"); final ClientConfiguration settings = new ClientConfiguration(); // Should be the default, but just to make it explicit settings.setProtocol(Protocol.HTTPS); // Helpers// w ww.j a va 2 s .co m Function<String, Long> getMillis = k -> cfg.getDuration(k, TimeUnit.MILLISECONDS); Function<String, Integer> getTimeout = k -> getMillis.apply(k).intValue(); // Typically use the defaults setIfPresent(cfg, "use-gzip", cfg::getBoolean, settings::setUseGzip); setIfPresent(cfg, "use-reaper", cfg::getBoolean, settings::setUseReaper); setIfPresent(cfg, "use-tcp-keep-alive", cfg::getBoolean, settings::setUseTcpKeepAlive); setIfPresent(cfg, "use-throttle-retries", cfg::getBoolean, settings::setUseThrottleRetries); setIfPresent(cfg, "max-connections", cfg::getInt, settings::setMaxConnections); setIfPresent(cfg, "max-error-retry", cfg::getInt, settings::setMaxErrorRetry); setIfPresent(cfg, "connection-ttl", getMillis, settings::setConnectionTTL); setIfPresent(cfg, "connection-max-idle", getMillis, settings::setConnectionMaxIdleMillis); setIfPresent(cfg, "connection-timeout", getTimeout, settings::setConnectionTimeout); setIfPresent(cfg, "socket-timeout", getTimeout, settings::setSocketTimeout); setIfPresent(cfg, "client-execution-timeout", getTimeout, settings::setClientExecutionTimeout); setIfPresent(cfg, "user-agent-prefix", cfg::getString, settings::setUserAgentPrefix); setIfPresent(cfg, "user-agent-suffix", cfg::getString, settings::setUserAgentSuffix); setIfPresent(cfg, "proxy-port", cfg::getInt, settings::setProxyPort); setIfPresent(cfg, "proxy-host", cfg::getString, settings::setProxyHost); setIfPresent(cfg, "proxy-domain", cfg::getString, settings::setProxyDomain); setIfPresent(cfg, "proxy-workstation", cfg::getString, settings::setProxyWorkstation); setIfPresent(cfg, "proxy-username", cfg::getString, settings::setProxyUsername); setIfPresent(cfg, "proxy-password", cfg::getString, settings::setProxyPassword); return settings; }