Skip to content

Commit 7760113

Browse files
committed
Implement ParameterStoreExceptionHappenedAnalyzer for exception that happen during loading.
1 parent 425b6c8 commit 7760113

File tree

5 files changed

+67
-27
lines changed

5 files changed

+67
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2013-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.awspring.cloud.autoconfigure.config.parameterstore;
17+
18+
public class AwsParameterPropertySourceNotFoundException extends RuntimeException {
19+
20+
AwsParameterPropertySourceNotFoundException(Exception source) {
21+
super(source);
22+
}
23+
24+
}

spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/parameterstore/ParameterStoreConfigDataLoader.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.springframework.boot.context.config.ConfigData;
2323
import org.springframework.boot.context.config.ConfigDataLoader;
2424
import org.springframework.boot.context.config.ConfigDataLoaderContext;
25-
import org.springframework.boot.context.config.ConfigDataResourceNotFoundException;
2625
import org.springframework.boot.logging.DeferredLogFactory;
2726
import org.springframework.core.env.MapPropertySource;
2827
import org.springframework.lang.Nullable;
@@ -47,28 +46,23 @@ public ParameterStoreConfigDataLoader(DeferredLogFactory logFactory) {
4746
@Override
4847
@Nullable
4948
public ConfigData load(ConfigDataLoaderContext context, ParameterStoreConfigDataResource resource) {
50-
try {
51-
// resource is disabled if parameter store integration is disabled via
52-
// spring.cloud.aws.parameterstore.enabled=false
53-
if (resource.isEnabled()) {
54-
SsmClient ssm = context.getBootstrapContext().get(SsmClient.class);
55-
ParameterStorePropertySource propertySource = resource.getPropertySources()
56-
.createPropertySource(resource.getContext(), resource.isOptional(), ssm);
57-
if (propertySource != null) {
58-
return new ConfigData(Collections.singletonList(propertySource));
59-
}
60-
else {
61-
return null;
62-
}
49+
// resource is disabled if parameter store integration is disabled via
50+
// spring.cloud.aws.parameterstore.enabled=false
51+
if (resource.isEnabled()) {
52+
SsmClient ssm = context.getBootstrapContext().get(SsmClient.class);
53+
ParameterStorePropertySource propertySource = resource.getPropertySources()
54+
.createPropertySource(resource.getContext(), resource.isOptional(), ssm);
55+
if (propertySource != null) {
56+
return new ConfigData(Collections.singletonList(propertySource));
6357
}
6458
else {
65-
// create dummy empty config data
66-
return new ConfigData(
67-
Collections.singletonList(new MapPropertySource("aws-parameterstore:" + context, Map.of())));
59+
return null;
6860
}
6961
}
70-
catch (Exception e) {
71-
throw new ConfigDataResourceNotFoundException(resource, e);
62+
else {
63+
// create dummy empty config data
64+
return new ConfigData(
65+
Collections.singletonList(new MapPropertySource("aws-parameterstore:" + context, Map.of())));
7266
}
7367
}
7468

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2013-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.awspring.cloud.autoconfigure.config.parameterstore;
17+
18+
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
19+
import org.springframework.boot.diagnostics.FailureAnalysis;
20+
21+
public class ParameterStoreExceptionHappenedAnalyzer
22+
extends AbstractFailureAnalyzer<AwsParameterPropertySourceNotFoundException> {
23+
24+
@Override
25+
protected FailureAnalysis analyze(Throwable rootFailure, AwsParameterPropertySourceNotFoundException cause) {
26+
return new FailureAnalysis("Could not import properties from AWS Parameter Store: " + cause.getMessage(),
27+
"Depending on error message determine action course", cause);
28+
}
29+
}

spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/parameterstore/ParameterStorePropertySources.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,4 @@ public ParameterStorePropertySource createPropertySource(String context, boolean
5757
return null;
5858
}
5959

60-
static class AwsParameterPropertySourceNotFoundException extends RuntimeException {
61-
62-
AwsParameterPropertySourceNotFoundException(Exception source) {
63-
super(source);
64-
}
65-
66-
}
67-
6860
}

spring-cloud-aws-autoconfigure/src/main/resources/META-INF/spring.factories

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ io.awspring.cloud.autoconfigure.config.s3.S3ConfigDataLoader
1313
# Failure Analyzers
1414
org.springframework.boot.diagnostics.FailureAnalyzer=\
1515
io.awspring.cloud.autoconfigure.config.parameterstore.ParameterStoreMissingKeysFailureAnalyzer, \
16+
io.awspring.cloud.autoconfigure.config.parameterstore.ParameterStoreExceptionHappenedAnalyzer, \
1617
io.awspring.cloud.autoconfigure.config.secretsmanager.SecretsManagerMissingKeysFailureAnalyzer,\
1718
io.awspring.cloud.autoconfigure.config.s3.S3MissingKeysFailureAnalyzer

0 commit comments

Comments
 (0)