Updating MultiLangDaemonConfiguration

Allowing the ability to set the region for kinesisClient, dynamoDbClient, cloudWatchClient separately and having regionName act as the default for all in the abscense of the new properties available.

Added a new private setRegionForClient method which takes a boolean argument of 'override'. This new method will set the property regardless if it's already set if override is true. If override is false, the method checks to see if the property has been set and only set the property if it's empty.

The reason for the new method is to allow for the properties to be loaded in any order during consumption of properties file without overriding any properties unexpectedly.
This commit is contained in:
dmatriccino 2022-04-15 16:24:08 -06:00
parent a344ee4d05
commit 039f508da1

View file

@ -269,10 +269,36 @@ public class MultiLangDaemonConfiguration {
}
}
private void setRegionForClient(String name, BuilderDynaBean client, Region region, boolean override) {
if(override) {
setRegionForClient(name, client, region);
} else {
String propertyValue;
try {
propertyValue = utilsBean.getProperty(client,"region");
//Check if property is already set. If not, set region for client
if(propertyValue == null || propertyValue.isEmpty()) {
setRegionForClient(name, client, region);
}
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
log.error("Failed to get region on {}", name, e);
throw new IllegalStateException(e);
}
}
}
public void setRegionName(Region region) {
setRegionForClient("kinesisClient", kinesisClient, region);
setRegionForClient("dynamoDbClient", dynamoDbClient, region);
setRegionForClient("cloudWatchClient", cloudWatchClient, region);
setRegionForClient("kinesisClient", kinesisClient, region, false);
setRegionForClient("dynamoDbClient", dynamoDbClient, region, false);
setRegionForClient("cloudWatchClient", cloudWatchClient, region, false);
}
public void setDynamoDBRegionName(Region region) {
setRegionForClient("dynamoDbClient", dynamoDbClient, region, true);
}
public void setCloudWatchRegionName(Region region) {
setRegionForClient("cloudWatchClient", cloudWatchClient, region, true);
}
private void setEndpointForClient(String name, BuilderDynaBean client, String endpoint) {