SGF-521 - Apply additional configuration changes.

This commit is contained in:
ukohlmeyer
2019-01-25 10:27:05 -08:00
committed by John Blum
parent 80c1597f66
commit 4456decd6e
4 changed files with 89 additions and 50 deletions

View File

@@ -1,8 +1,13 @@
package org.springframework.data.gemfire.wan.annotation;
import org.springframework.context.annotation.Import;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
import org.springframework.context.annotation.Import;
/**
* The EnableGatewayReceiver annotation creates a {@link org.apache.geode.cache.wan.GatewayReceiver}
@@ -26,23 +31,26 @@ public @interface EnableGatewayReceiver {
/**
* A boolean to allow the GatewayReceiver to be created without being started after creation.
* If the manualStart is set to {@literal true} then the system will create the GatewayReceiver but not start it.
* If the manualStart is set to <b><i>true</i></b> then the system will create the GatewayReceiver but not start it.
* It then becomes the responsibility of the operator to start the GatewayReceiver at a later stage.
* If set to {@literal false} the GatewayReceiver will start automatically after creation.
* If set to <b><i>false</i></b> the GatewayReceiver will start automatically after creation.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.manual-start</i></b> property<br>
* Default is {@value EnableGatewayReceiverConfiguration#DEFAULT_MANUAL_START}
*/
boolean manualStart() default EnableGatewayReceiverConfiguration.DEFAULT_MANUAL_START;
/**
* The starting port number that GatewayReceiver will use when selecting a port to run on. This range of port numbers
* is bounded by the {startPort} and {endPort}.
* The starting port that GatewayReceiver will use when selecting a port to run on. This range of port numbers
* is bounded by a <b><i>startPort</i></b> and <b><i>endPort</i></b>.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.start-port</i></b> property<br>
* Default is {@value EnableGatewayReceiverConfiguration#DEFAULT_START_PORT}
*/
int startPort() default EnableGatewayReceiverConfiguration.DEFAULT_START_PORT;
/**
* The end port number that GatewayReceiver will use when selecting a port to run on. This range of port numbers
* is bounded by the {startPort} and {endPort}.
* The end port that GatewayReceiver will use when selecting a port to run on. This range of port numbers
* is bounded by a <b><i>startPort</i></b> and <b><i>endPort</i></b>.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.end-port</i></b> property<br>
* Default is {@value EnableGatewayReceiverConfiguration#DEFAULT_END_PORT}
*/
int endPort() default EnableGatewayReceiverConfiguration.DEFAULT_END_PORT;
@@ -50,27 +58,31 @@ public @interface EnableGatewayReceiver {
/**
* An integer value in milliseconds representing the maximum time which a {@link org.apache.geode.cache.wan.GatewayReceiver}
* will wait to receive a ping back from a {@link org.apache.geode.cache.wan.GatewaySender} before the {@link org.apache.geode.cache.wan.GatewayReceiver}
* believes the sender to be not available.
* believes the sender to be not available.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.maximum-time-between-pings</i></b> property<br>
* Default value is {@value EnableGatewayReceiverConfiguration#DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS}
*/
int maximumTimeBetweenPings() default EnableGatewayReceiverConfiguration.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS;
/**
* The socket buffer size for the {@link org.apache.geode.cache.wan.GatewayReceiver}. This setting is in bytes
* The socket buffer size for the {@link org.apache.geode.cache.wan.GatewayReceiver}. This setting is in bytes.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.socket-buffer-size</i></b> property<br>
* Default value is {@value EnableGatewayReceiverConfiguration#DEFAULT_SOCKET_BUFFER_SIZE}
*/
int socketBufferSize() default EnableGatewayReceiverConfiguration.DEFAULT_SOCKET_BUFFER_SIZE;
/**
* An in-order list of {@link org.apache.geode.cache.wan.GatewayTransportFilter} to be applied to
* {@link org.apache.geode.cache.wan.GatewayReceiver}
* Default value is {@value {}}
* {@link org.apache.geode.cache.wan.GatewayReceiver}<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.transport-filters</i></b> property<br>
* Default value is an empty String array
*/
String[] transportFilters() default {};
/**
* The IP address or hostname that the {@link org.apache.geode.cache.wan.GatewayReceiver} communication socket will be bound to.
* An empty String will cause the underlying socket to bind to 0.0.0.0
* An empty String will cause the underlying socket to bind to 0.0.0.0<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.bind-address</i></b> property <br>
* Default value is {@value EnableGatewayReceiverConfiguration#DEFAULT_BIND_ADDRESS}
*/
String bindAddress() default EnableGatewayReceiverConfiguration.DEFAULT_BIND_ADDRESS;
@@ -81,7 +93,8 @@ public @interface EnableGatewayReceiver {
* to the {@link org.apache.geode.cache.wan.GatewaySender}. Generally this property is set when there are multiple
* network interfaces or when they are designated as "internal" or "public" network interfaces. In a cloud environment
* the notion of external and internal network interfaces exist and generally the "externally"/outwardly facing network
* interface is used.
* interface is used.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.hostname-for-senders</i></b> property<br>
* Default value is {@value EnableGatewayReceiverConfiguration#DEFAULT_HOSTNAME_FOR_SENDERS}
*/
String hostnameForSenders() default EnableGatewayReceiverConfiguration.DEFAULT_HOSTNAME_FOR_SENDERS;

View File

@@ -1,5 +1,9 @@
package org.springframework.data.gemfire.wan.annotation;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Optional;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanReference;
@@ -14,10 +18,6 @@ import org.springframework.data.gemfire.config.annotation.support.AbstractAnnota
import org.springframework.data.gemfire.config.xml.GemfireConstants;
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Optional;
/**
* Spring {@link Configuration} class used to construct, configure and initialize a {@link GatewayReceiver} instance
* in a Spring application context.
@@ -39,8 +39,9 @@ public class EnableGatewayReceiverConfiguration extends AbstractAnnotationConfig
static final int DEFAULT_SOCKET_BUFFER_SIZE = GatewayReceiver.DEFAULT_SOCKET_BUFFER_SIZE;
static final String DEFAULT_BIND_ADDRESS = GatewayReceiver.DEFAULT_BIND_ADDRESS;
static final String DEFAULT_HOSTNAME_FOR_SENDERS = GatewayReceiver.DEFAULT_HOSTNAME_FOR_SENDERS;
private final String START_PORT_LITERAL = "startPort";
private final String END_PORT_LITERAL = "END_PORT_LITERAL";
private final String END_PORT_LITERAL = "endPort";
private final String MANUAL_START_LITERAL = "manualStart";
private final String MAXIMUM_TIME_BETWEEN_PINGS_LITERAL = "maximumTimeBetweenPings";
private final String SOCKET_BUFFER_SIZE_LITERAL = "socketBufferSize";
@@ -48,6 +49,15 @@ public class EnableGatewayReceiverConfiguration extends AbstractAnnotationConfig
private final String HOSTNAME_FOR_SENDERS_LITERAL = "hostnameForSenders";
private final String TRANSPORT_FILTERS_LITERAL = "transportFilters";
private final String START_PORT_PROPERTY_LITERAL = "start-port";
private final String END_PORT_PROPERTY_LITERAL = "end-port";
private final String MANUAL_START_PROPERTY_LITERAL = "manual-start";
private final String MAXIMUM_TIME_BETWEEN_PINGS_PROPERTY_LITERAL = "maximum-time-between-pings";
private final String SOCKET_BUFFER_SIZE_PROPERTY_LITERAL = "socket-buffer-size";
private final String BIND_ADDRESS_PROPERTY_LITERAL = "bind-address";
private final String HOSTNAME_FOR_SENDERS_PROPERTY_LITERAL = "hostname-for-senders";
private final String TRANSPORT_FILTERS_PROPERTY_LITERAL = "transport-filters";
@Override
protected Class<? extends Annotation> getAnnotationType() {
return org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiver.class;
@@ -65,8 +75,8 @@ public class EnableGatewayReceiverConfiguration extends AbstractAnnotationConfig
}
/**
* Configures a {@link GatewayReceiver} from the {@link EnableGatewayReceiver} annotation, "spring.data.gemfire.gateway.receiver.*"
* properties and {@link EnableGatewayReceiverConfigurer}
* Configures a {@link GatewayReceiver} from the {@link EnableGatewayReceiver} annotation, <b><i>spring.data.gemfire.gateway.receiver.*</i></b>
* properties or {@link EnableGatewayReceiverConfigurer}
*
* @param enableGatewayReceiverAttributes
* @param registry
@@ -132,7 +142,7 @@ public class EnableGatewayReceiverConfiguration extends AbstractAnnotationConfig
}
/**
* Configures GatewayReceiver {@link BeanDefinitionBuilder} using properties, defined under "spring.data.gemfire.gateway.receiver.*"
* Configures GatewayReceiver {@link BeanDefinitionBuilder} using properties, defined under <b><i>spring.data.gemfire.gateway.receiver.*</i></b>
*
* @param gatewayReceiverBeanBuilder
*/
@@ -140,22 +150,31 @@ public class EnableGatewayReceiverConfiguration extends AbstractAnnotationConfig
BeanDefinitionBuilder gatewayReceiverBeanBuilder) {
MutablePropertyValues beanPropertyValues = gatewayReceiverBeanBuilder.getRawBeanDefinition()
.getPropertyValues();
configureFromProperties(gatewayReceiverBeanBuilder, START_PORT_LITERAL,
configureFromProperties(gatewayReceiverBeanBuilder, START_PORT_LITERAL, START_PORT_PROPERTY_LITERAL,
(Integer) beanPropertyValues.getPropertyValue(START_PORT_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, END_PORT_LITERAL,
configureFromProperties(gatewayReceiverBeanBuilder, END_PORT_LITERAL, END_PORT_PROPERTY_LITERAL,
(Integer) beanPropertyValues.getPropertyValue(END_PORT_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, MANUAL_START_LITERAL,
configureFromProperties(gatewayReceiverBeanBuilder, MANUAL_START_LITERAL, MANUAL_START_PROPERTY_LITERAL,
(Boolean) beanPropertyValues.getPropertyValue(MANUAL_START_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, MAXIMUM_TIME_BETWEEN_PINGS_LITERAL,
MAXIMUM_TIME_BETWEEN_PINGS_PROPERTY_LITERAL,
(Integer) beanPropertyValues.getPropertyValue(MAXIMUM_TIME_BETWEEN_PINGS_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, SOCKET_BUFFER_SIZE_LITERAL,
SOCKET_BUFFER_SIZE_PROPERTY_LITERAL,
(Integer) beanPropertyValues.getPropertyValue(SOCKET_BUFFER_SIZE_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, BIND_ADDRESS_LITERAL,
configureFromProperties(gatewayReceiverBeanBuilder, BIND_ADDRESS_LITERAL, BIND_ADDRESS_PROPERTY_LITERAL,
(String) beanPropertyValues.getPropertyValue(BIND_ADDRESS_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, HOSTNAME_FOR_SENDERS_LITERAL,
HOSTNAME_FOR_SENDERS_PROPERTY_LITERAL,
(String) beanPropertyValues.getPropertyValue(HOSTNAME_FOR_SENDERS_LITERAL).getValue());
String[] filters = resolveProperty(gatewayReceiverProperty(TRANSPORT_FILTERS_LITERAL), String[].class);
String[] filters = resolveProperty(gatewayReceiverProperty(TRANSPORT_FILTERS_PROPERTY_LITERAL), String[].class);
Optional.ofNullable(filters)
.ifPresent(transportFilters ->
{
@@ -164,23 +183,26 @@ public class EnableGatewayReceiverConfiguration extends AbstractAnnotationConfig
});
}
private void configureFromProperties(BeanDefinitionBuilder gatewayReceiverBeanBuilder, String propertyName,
private void configureFromProperties(BeanDefinitionBuilder gatewayReceiverBeanBuilder, String beanPropertyName,
String propertyName,
Integer annotatedPropertyValue) {
Integer propertyValue = resolveProperty(gatewayReceiverProperty(propertyName), annotatedPropertyValue);
gatewayReceiverBeanBuilder.addPropertyValue(propertyName, propertyValue);
gatewayReceiverBeanBuilder.addPropertyValue(beanPropertyName, propertyValue);
}
private void configureFromProperties(BeanDefinitionBuilder gatewayReceiverBeanBuilder, String propertyName,
private void configureFromProperties(BeanDefinitionBuilder gatewayReceiverBeanBuilder, String beanPropertyName,
String propertyName,
String annotatedPropertyValue) {
String propertyValue = resolveProperty(gatewayReceiverProperty(propertyName), annotatedPropertyValue);
gatewayReceiverBeanBuilder.addPropertyValue(propertyName, propertyValue);
gatewayReceiverBeanBuilder.addPropertyValue(beanPropertyName, propertyValue);
}
private void configureFromProperties(BeanDefinitionBuilder gatewayReceiverBeanBuilder, String propertyName,
private void configureFromProperties(BeanDefinitionBuilder gatewayReceiverBeanBuilder, String beanPropertyName,
String propertyName,
Boolean annotatedPropertyValue) {
Boolean propertyValue = resolveProperty(gatewayReceiverProperty(propertyName), annotatedPropertyValue);
gatewayReceiverBeanBuilder.addPropertyValue(propertyName, propertyValue);
gatewayReceiverBeanBuilder.addPropertyValue(beanPropertyName, propertyValue);
}
private ManagedList<BeanReference> resolveTransportBeanReferences(String[] transportFilters) {

View File

@@ -93,14 +93,14 @@ public class EnableEnableGatewayReceiverConfigurerTests {
public void gatewayReceiverConfigurerWithPropertiesConfiguration() {
MockPropertySource testPropertySource = new MockPropertySource()
.withProperty("spring.data.gemfire.gateway.receiver.bindAddress", "123.123.123.123")
.withProperty("spring.data.gemfire.gateway.receiver.hostnameForSenders", "testHostName")
.withProperty("spring.data.gemfire.gateway.receiver.startPort", 16000)
.withProperty("spring.data.gemfire.gateway.receiver.endPort", 17000)
.withProperty("spring.data.gemfire.gateway.receiver.maximumTimeBetweenPings", 30000)
.withProperty("spring.data.gemfire.gateway.receiver.socketBufferSize", 32768)
.withProperty("spring.data.gemfire.gateway.receiver.manualStart", true)
.withProperty("spring.data.gemfire.gateway.receiver.transportFilters", "transportBean1,transportBean2");
.withProperty("spring.data.gemfire.gateway.receiver.bind-address", "123.123.123.123")
.withProperty("spring.data.gemfire.gateway.receiver.hostname-for-senders", "testHostName")
.withProperty("spring.data.gemfire.gateway.receiver.start-port", 16000)
.withProperty("spring.data.gemfire.gateway.receiver.end-port", 17000)
.withProperty("spring.data.gemfire.gateway.receiver.maximum-time-between-pings", 30000)
.withProperty("spring.data.gemfire.gateway.receiver.socket-buffer-size", 32768)
.withProperty("spring.data.gemfire.gateway.receiver.manual-start", true)
.withProperty("spring.data.gemfire.gateway.receiver.transport-filters", "transportBean1,transportBean2");
this.applicationContext = newApplicationContext(testPropertySource,
EnableEnableGatewayReceiverConfigurerTests.TestConfigurationWithProperties.class);
@@ -127,11 +127,11 @@ public class EnableEnableGatewayReceiverConfigurerTests {
public void gatewayReceiverConfigurerWithPropertiesAndAnnotationConfiguration() {
MockPropertySource testPropertySource = new MockPropertySource()
.withProperty("spring.data.gemfire.gateway.receiver.hostnameForSenders", "testHostName")
.withProperty("spring.data.gemfire.gateway.receiver.maximumTimeBetweenPings", 30000)
.withProperty("spring.data.gemfire.gateway.receiver.socketBufferSize", 32768)
.withProperty("spring.data.gemfire.gateway.receiver.manualStart", true)
.withProperty("spring.data.gemfire.gateway.receiver.transportFilters", "transportBean2,transportBean1");
.withProperty("spring.data.gemfire.gateway.receiver.hostname-for-senders", "testHostName")
.withProperty("spring.data.gemfire.gateway.receiver.maximum-time-between-pings", 30000)
.withProperty("spring.data.gemfire.gateway.receiver.socket-buffer-size", 32768)
.withProperty("spring.data.gemfire.gateway.receiver.manual-start", true)
.withProperty("spring.data.gemfire.gateway.receiver.transport-filters", "transportBean2,transportBean1");
this.applicationContext = newApplicationContext(testPropertySource,
EnableEnableGatewayReceiverConfigurerTests.TestConfiguration.class);

View File

@@ -2,6 +2,14 @@ package org.springframework.data.gemfire.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.apache.geode.cache.wan.GatewayTransportFilter;
import org.junit.After;
@@ -16,10 +24,6 @@ import org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiver;
import org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiverConfiguration;
import org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiverConfigurer;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*;
/**
* Tests for {@link org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiver}.
*