Skip to content

Commit 9cb701b

Browse files
authored
Add a property to configure the max error retry on the ssm client use… (#63)
* Add a property to configure the max error retry on the ssm client used in the property source. * Bump version in the read me
1 parent 03361e3 commit 9cb701b

10 files changed

+134
-35
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.coveo</groupId>
77
<artifactId>spring-boot-parameter-store-integration</artifactId>
8-
<version>1.4.0</version>
8+
<version>1.5.0</version>
99

1010
<name>Spring Boot Parameter Store Integration</name>
1111
<description>An integration of Amazon Web Services' Systems Manager Parameter Store for Spring Boot's properties injection.</description>

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The library was tested and worked properly with:
2626
<dependency>
2727
<groupId>com.coveo</groupId>
2828
<artifactId>spring-boot-parameter-store-integration</artifactId>
29-
<version>1.4.0</version>
29+
<version>1.5.0</version>
3030
</dependency>
3131
```
3232

src/main/java/com/coveo/configuration/parameterstore/ParameterStorePropertySourceConfigurationProperties.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
public final class ParameterStorePropertySourceConfigurationProperties
44
{
5+
private static final String SSM_CLIENT = "ssmClient";
56
private static final String PROPERTY_SOURCE_PREFIX = "awsParameterStorePropertySource";
67
private static final String SOURCE_PREFIX = "awsParameterStoreSource";
78
private static final String SSM_CLIENT_ENDPOINT_CONFIG_PREFIX = joinWithDot(SOURCE_PREFIX,
8-
"ssmClient",
9+
SSM_CLIENT,
910
"endpointConfiguration");
1011

1112
public static final String ENABLED_PROFILE = "awsParameterStorePropertySourceEnabled";
@@ -19,8 +20,9 @@ public final class ParameterStorePropertySourceConfigurationProperties
1920
"signingRegion");
2021
public static final String MULTI_REGION_SSM_CLIENT_REGIONS = joinWithDot(SOURCE_PREFIX,
2122
"multiRegion",
22-
"ssmClient",
23+
SSM_CLIENT,
2324
"regions");
25+
public static final String MAX_ERROR_RETRY = joinWithDot(SOURCE_PREFIX, SSM_CLIENT, "maxErrorRetry");
2426

2527
private static String joinWithDot(String... elements)
2628
{

src/main/java/com/coveo/configuration/parameterstore/ParameterStorePropertySourceEnvironmentPostProcessor.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import org.springframework.core.env.ConfigurableEnvironment;
77
import org.springframework.util.ObjectUtils;
88

9+
import com.amazonaws.ClientConfigurationFactory;
10+
import com.amazonaws.retry.PredefinedRetryPolicies;
11+
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder;
912
import com.coveo.configuration.parameterstore.strategy.ParameterStorePropertySourceConfigurationStrategy;
1013
import com.coveo.configuration.parameterstore.strategy.ParameterStorePropertySourceConfigurationStrategyFactory;
1114
import com.coveo.configuration.parameterstore.strategy.StrategyType;
@@ -18,10 +21,20 @@ public class ParameterStorePropertySourceEnvironmentPostProcessor implements Env
1821
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application)
1922
{
2023
if (isParameterStorePropertySourceEnabled(environment)) {
21-
getParameterStorePropertySourceConfigurationStrategy(environment).configureParameterStorePropertySources(environment);
24+
getParameterStorePropertySourceConfigurationStrategy(environment).configureParameterStorePropertySources(environment,
25+
preconfigureSSMClientBuilder(environment));
2226
}
2327
}
2428

29+
private AWSSimpleSystemsManagementClientBuilder preconfigureSSMClientBuilder(ConfigurableEnvironment environment)
30+
{
31+
return AWSSimpleSystemsManagementClientBuilder.standard()
32+
.withClientConfiguration(new ClientConfigurationFactory().getConfig()
33+
.withRetryPolicy(PredefinedRetryPolicies.getDefaultRetryPolicyWithCustomMaxRetries(environment.getProperty(ParameterStorePropertySourceConfigurationProperties.MAX_ERROR_RETRY,
34+
Integer.class,
35+
PredefinedRetryPolicies.DEFAULT_MAX_ERROR_RETRY))));
36+
}
37+
2538
private ParameterStorePropertySourceConfigurationStrategy getParameterStorePropertySourceConfigurationStrategy(ConfigurableEnvironment environment)
2639
{
2740
StrategyType type = isMultiRegionEnabled(environment) ? StrategyType.MULTI_REGION : StrategyType.DEFAULT;

src/main/java/com/coveo/configuration/parameterstore/strategy/DefaultParameterStorePropertySourceConfigurationStrategy.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.amazonaws.regions.AwsRegionProviderChain;
77
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
88
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder;
9-
109
import com.coveo.configuration.parameterstore.ParameterStorePropertySource;
1110
import com.coveo.configuration.parameterstore.ParameterStorePropertySourceConfigurationProperties;
1211
import com.coveo.configuration.parameterstore.ParameterStoreSource;
@@ -24,13 +23,15 @@ public DefaultParameterStorePropertySourceConfigurationStrategy(AwsRegionProvide
2423
}
2524

2625
@Override
27-
public void configureParameterStorePropertySources(ConfigurableEnvironment environment)
26+
public void configureParameterStorePropertySources(ConfigurableEnvironment environment,
27+
AWSSimpleSystemsManagementClientBuilder ssmClientBuilder)
2828
{
2929
boolean haltBoot = environment.getProperty(ParameterStorePropertySourceConfigurationProperties.HALT_BOOT,
3030
Boolean.class,
3131
Boolean.FALSE);
3232
environment.getPropertySources()
33-
.addFirst(buildParameterStorePropertySource(buildSSMClient(environment), haltBoot));
33+
.addFirst(buildParameterStorePropertySource(buildSSMClient(environment, ssmClientBuilder),
34+
haltBoot));
3435
}
3536

3637
private ParameterStorePropertySource buildParameterStorePropertySource(AWSSimpleSystemsManagement ssmClient,
@@ -40,15 +41,15 @@ private ParameterStorePropertySource buildParameterStorePropertySource(AWSSimple
4041
new ParameterStoreSource(ssmClient, haltBoot));
4142
}
4243

43-
private AWSSimpleSystemsManagement buildSSMClient(ConfigurableEnvironment environment)
44+
private AWSSimpleSystemsManagement buildSSMClient(ConfigurableEnvironment environment,
45+
AWSSimpleSystemsManagementClientBuilder ssmClientBuilder)
4446
{
4547
if (hasCustomEndpoint(environment)) {
46-
return AWSSimpleSystemsManagementClientBuilder.standard()
47-
.withEndpointConfiguration(new EndpointConfiguration(getCustomEndpoint(environment),
48-
getSigningRegion(environment)))
49-
.build();
48+
return ssmClientBuilder.withEndpointConfiguration(new EndpointConfiguration(getCustomEndpoint(environment),
49+
getSigningRegion(environment)))
50+
.build();
5051
}
51-
return AWSSimpleSystemsManagementClientBuilder.defaultClient();
52+
return ssmClientBuilder.build();
5253
}
5354

5455
private boolean hasCustomEndpoint(ConfigurableEnvironment environment)

src/main/java/com/coveo/configuration/parameterstore/strategy/MultiRegionParameterStorePropertySourceConfigurationStrategy.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
1010
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder;
11-
1211
import com.coveo.configuration.parameterstore.ParameterStorePropertySource;
1312
import com.coveo.configuration.parameterstore.ParameterStorePropertySourceConfigurationProperties;
1413
import com.coveo.configuration.parameterstore.ParameterStoreSource;
@@ -19,7 +18,8 @@ public class MultiRegionParameterStorePropertySourceConfigurationStrategy
1918
private static final String PARAMETER_STORE_PROPERTY_SOURCE_NAME = "MultiRegionAWSParameterStorePropertySource_";
2019

2120
@Override
22-
public void configureParameterStorePropertySources(ConfigurableEnvironment environment)
21+
public void configureParameterStorePropertySources(ConfigurableEnvironment environment,
22+
AWSSimpleSystemsManagementClientBuilder ssmClientBuilder)
2323
{
2424
boolean haltBoot = environment.getProperty(ParameterStorePropertySourceConfigurationProperties.HALT_BOOT,
2525
Boolean.class,
@@ -35,23 +35,29 @@ public void configureParameterStorePropertySources(ConfigurableEnvironment envir
3535
String lastRegion = regions.get(0);
3636

3737
// We only want to halt boot (if true) for the last region
38-
environment.getPropertySources().addFirst(buildParameterStorePropertySource(lastRegion, haltBoot));
38+
environment.getPropertySources()
39+
.addFirst(buildParameterStorePropertySource(ssmClientBuilder, lastRegion, haltBoot));
3940

4041
regions.stream()
4142
.skip(1)
4243
.forEach(region -> environment.getPropertySources()
43-
.addFirst(buildParameterStorePropertySource(region, false)));
44+
.addFirst(buildParameterStorePropertySource(ssmClientBuilder,
45+
region,
46+
false)));
4447
}
4548

46-
private ParameterStorePropertySource buildParameterStorePropertySource(String region, boolean haltBoot)
49+
private ParameterStorePropertySource buildParameterStorePropertySource(AWSSimpleSystemsManagementClientBuilder ssmClientBuilder,
50+
String region,
51+
boolean haltBoot)
4752
{
48-
return new ParameterStorePropertySource(PARAMETER_STORE_PROPERTY_SOURCE_NAME + region,
49-
new ParameterStoreSource(buildSSMClient(region), haltBoot));
53+
return new ParameterStorePropertySource(PARAMETER_STORE_PROPERTY_SOURCE_NAME
54+
+ region, new ParameterStoreSource(buildSSMClient(ssmClientBuilder, region), haltBoot));
5055
}
5156

52-
private AWSSimpleSystemsManagement buildSSMClient(String region)
57+
private AWSSimpleSystemsManagement buildSSMClient(AWSSimpleSystemsManagementClientBuilder ssmClientBuilder,
58+
String region)
5359
{
54-
return AWSSimpleSystemsManagementClientBuilder.standard().withRegion(region).build();
60+
return ssmClientBuilder.withRegion(region).build();
5561
}
5662

5763
private List<String> getRegions(ConfigurableEnvironment environment)

src/main/java/com/coveo/configuration/parameterstore/strategy/ParameterStorePropertySourceConfigurationStrategy.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import org.springframework.core.env.ConfigurableEnvironment;
44

5+
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder;
6+
57
public interface ParameterStorePropertySourceConfigurationStrategy
68
{
7-
void configureParameterStorePropertySources(ConfigurableEnvironment environment);
9+
void configureParameterStorePropertySources(ConfigurableEnvironment environment,
10+
AWSSimpleSystemsManagementClientBuilder ssmClientBuilder);
811
}

0 commit comments

Comments
 (0)