Skip to content

Commit 078e1e5

Browse files
vishnu-alapatiVishnu
andauthored
Know and Define Timeouts for REMRem Dependencies (#237)
* TCP Connection timeout changes Co-authored-by: Vishnu <vishnu.alapati@ericsson.com>
1 parent cdb5190 commit 078e1e5

File tree

14 files changed

+120
-26
lines changed

14 files changed

+120
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 2.0.25
22
- Implemented "publisher confirms " in REMReM so that this can be used to get confirmation about the messages sent to MB.
3+
- Implemented configurable parameters for TCP connection timeout against LDAP and MB
34

45
## 2.0.24
56
- Updated all the curl commands in documentation

publish-cli/src/main/java/com/ericsson/eiffel/remrem/publish/cli/CliOptions.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static void createCLIOptions() {
8484
options.addOption("v", "lists the versions of publish and all loaded protocols");
8585
options.addOption("tag", "tag", true, "tag to be used in routing key");
8686
options.addOption("rk", "routing_key", true, "routing key of the eiffel message. When provided routing key is not generated and the value provided is used.");
87-
87+
options.addOption("tto", "tcp_time_out", true, "specifies tcp connection timeout, default time is 60000 milliseconds");
8888
contentGroup = createContentGroup();
8989
options.addOptionGroup(contentGroup);
9090
}
@@ -220,12 +220,19 @@ public static void handleMessageBusOptions() throws HandleMessageBusException {
220220
String key = PropertiesConfig.DOMAIN_ID;
221221
System.setProperty(key, domain);
222222
}
223+
223224
if (commandLine.hasOption("channelsCount")) {
224225
String channelsCount = commandLine.getOptionValue("channelsCount");
225226
String key = PropertiesConfig.CHANNELS_COUNT;
226227
System.setProperty(key, channelsCount);
227228
}
228229

230+
if (commandLine.hasOption("tto")) {
231+
String timeOut = commandLine.getOptionValue("tto");
232+
String key = PropertiesConfig.TCP_TIMEOUT;
233+
System.setProperty(key, timeOut);
234+
}
235+
229236
if (commandLine.hasOption("wcto")) {
230237
String timeOut = commandLine.getOptionValue("wcto");
231238
String key = PropertiesConfig.WAIT_FOR_CONFIRMS_TIME_OUT;
@@ -279,6 +286,7 @@ public static void clearSystemProperties() {
279286
System.clearProperty(PropertiesConfig.TLS);
280287
System.clearProperty(PropertiesConfig.DOMAIN_ID);
281288
System.clearProperty(PropertiesConfig.CHANNELS_COUNT);
289+
System.clearProperty(PropertiesConfig.TCP_TIMEOUT);
282290
System.clearProperty(PropertiesConfig.WAIT_FOR_CONFIRMS_TIME_OUT);
283291
}
284292

publish-cli/src/test/java/com/ericsson/eiffel/remrem/publish/cli/CliOptionsUnitTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,18 @@ public void testFOptionFails() throws Exception {
180180
int code = CLIExitCodes.CLI_MISSING_OPTION_EXCEPTION;
181181
assertTrue(CliOptions.getErrorCodes().contains(code));
182182
}
183+
184+
public void testTtoOption() throws Exception {
185+
String[] args = { "-f", "/a/b/c/test.file", "test", "-tto", "5000" };
186+
CliOptions.parse(args);
187+
assertTrue(CliOptions.getErrorCodes().isEmpty());
188+
}
189+
190+
@Test
191+
public void testTtoOptionFails() throws Exception {
192+
String[] args = { "-f", "/a/b/c/test.file", "test", "-ttof", "5000" };
193+
CliOptions.parse(args);
194+
int code = CLIExitCodes.CLI_MISSING_OPTION_EXCEPTION;
195+
assertTrue(CliOptions.getErrorCodes().contains(code));
196+
}
183197
}

publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/config/PropertiesConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class PropertiesConfig {
1919
public static final String MESSAGE_BUS_PORT = "com.ericsson.eiffel.remrem.publish.messagebus.port";
2020
public static final String VIRTUAL_HOST = "com.ericsson.eiffel.remrem.publish.messagebus.virtualhost";
2121
public static final String CHANNELS_COUNT = "com.ericsson.eiffel.remrem.publish.messagebus.channels";
22+
public static final String TCP_TIMEOUT = "com.ericsson.eiffel.remrem.publish.messagebus.tcpTimeOut";
2223
public static final String WAIT_FOR_CONFIRMS_TIME_OUT = "com.ericsson.eiffel.remrem.publish.messagebus.waitforconfirmstimeout";
2324
public static final String TLS = "com.ericsson.eiffel.remrem.publish.messagebus.tls";
2425
public static final String EXCHANGE_NAME = "com.ericsson.eiffel.remrem.publish.exchange.name";

publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/config/RabbitMqPropertiesConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ private void readSpringProperties() {
124124
rabbitmqInstanceObject.get("waitForConfirmsTimeOut").asText(),
125125
RabbitMqProperties.DEFAULT_WAIT_FOR_CONFIRMS_TIMEOUT));
126126
}
127+
if ((rabbitmqInstanceObject.get("tcpTimeOut") != null)) {
128+
rabbitMqProperties.setTcpTimeOut(Integer.getInteger(rabbitmqInstanceObject.get("tcpTimeOut").asText(),
129+
RabbitMqProperties.DEFAULT_TCP_TIMEOUT));
130+
}
127131
rabbitMqPropertiesMap.put(protocol, rabbitMqProperties);
128132
}
129133
} catch (Exception e) {

publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/helper/RabbitMqProperties.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public class RabbitMqProperties {
5252
private String domainId;
5353
private Integer channelsCount;
5454
private boolean createExchangeIfNotExisting;
55+
private Integer tcpTimeOut;
56+
// built in tcp connection timeout value for MB in milliseconds.
57+
public static final Integer DEFAULT_TCP_TIMEOUT = 60000;
5558
private Long waitForConfirmsTimeOut;
5659
public static final Long DEFAULT_WAIT_FOR_CONFIRMS_TIMEOUT = 5000L;
5760
public static final Integer DEFAULT_CHANNEL_COUNT = 1;
@@ -148,6 +151,14 @@ public void setChannelsCount(Integer channelsCount) {
148151
this.channelsCount = channelsCount;
149152
}
150153

154+
public Integer getTcpTimeOut() {
155+
return tcpTimeOut;
156+
}
157+
158+
public void setTcpTimeOut(Integer tcpTimeOut) {
159+
this.tcpTimeOut = tcpTimeOut;
160+
}
161+
151162
public RMQBeanConnectionFactory getFactory() {
152163
return factory;
153164
}
@@ -236,6 +247,10 @@ public void init() throws RemRemPublishException {
236247
*/
237248
public void createRabbitMqConnection() throws RemRemPublishException {
238249
try {
250+
if (tcpTimeOut == null || tcpTimeOut == 0) {
251+
tcpTimeOut = DEFAULT_TCP_TIMEOUT;
252+
}
253+
factory.setConnectionTimeout(tcpTimeOut);
239254
rabbitConnection = factory.newConnection();
240255
log.info("Connected to RabbitMQ.");
241256
rabbitChannels = new ArrayList<>();
@@ -293,6 +308,11 @@ private void initService() {
293308
if (channelsCount == null ) {
294309
channelsCount = Integer.getInteger(getValuesFromSystemProperties(protocol + ".rabbitmq.channelsCount"));
295310
}
311+
312+
if (tcpTimeOut == null) {
313+
tcpTimeOut = Integer.getInteger(getValuesFromSystemProperties(protocol + ".rabbitmq.tcpTimeOut"));
314+
}
315+
296316
if (waitForConfirmsTimeOut == null ) {
297317
waitForConfirmsTimeOut = Long.getLong(getValuesFromSystemProperties(protocol + ".rabbitmq.waitForConfirmsTimeOut"));
298318
}
@@ -310,6 +330,7 @@ private void setValues() {
310330
exchangeName = getValuesFromSystemProperties(PropertiesConfig.EXCHANGE_NAME);
311331
usePersitance = Boolean.getBoolean(PropertiesConfig.USE_PERSISTENCE);
312332
createExchangeIfNotExisting = Boolean.parseBoolean(getValuesFromSystemProperties(PropertiesConfig.CREATE_EXCHANGE_IF_NOT_EXISTING));
333+
tcpTimeOut = Integer.getInteger(PropertiesConfig.TCP_TIMEOUT);
313334
}
314335

315336
private String getValuesFromSystemProperties(String propertyName) {

publish-common/src/main/resources/config.template.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
eiffelsemantics.rabbitmq.exchangeName: amq.direct
2828
eiffelsemantics.rabbitmq.domainId: eiffelxxx
2929
eiffelsemantics.rabbitmq.channelsCount: 1
30+
eiffelsemantics.rabbitmq.tcpTimeOut: 5000
3031
eiffelsemantics.rabbitmq.waitForConfirmsTimeOut: 5000
3132

3233
# properties for server used to generate messages
@@ -43,3 +44,4 @@
4344
activedirectory.managerDn:
4445
activedirectory.rootDn:
4546
activedirectory.userSearchFilter:
47+
activedirectory.connectionTimeOut:

publish-common/src/test/java/com/ericsson/eiffel/remrem/publish/helper/RMQHelperUnitTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class RMQHelperUnitTest {
5656
private static final String usePersistence= "1.2";
5757
private static final String domainId= "eiffelxxx";
5858
private static final Integer channelsCount= 1;
59+
private static final Integer tcpTimeOut= 5000;
5960
private static final Long waitForConfirmTimeOut= 5000L;
6061
private String protocol = "eiffelsemantics";
6162
private String createExchange = "true";
@@ -100,6 +101,7 @@ private void initProperties() {
100101
System.setProperty(PropertiesConfig.CREATE_EXCHANGE_IF_NOT_EXISTING, createExchange);
101102
System.setProperty(PropertiesConfig.DOMAIN_ID, domainId);
102103
System.setProperty(PropertiesConfig.CHANNELS_COUNT, Integer.toString(channelsCount));
104+
System.setProperty(PropertiesConfig.TCP_TIMEOUT, Integer.toString(tcpTimeOut));
103105
System.setProperty(PropertiesConfig.WAIT_FOR_CONFIRMS_TIME_OUT, Long.toString(waitForConfirmTimeOut));
104106
}
105107

@@ -115,6 +117,7 @@ private void cleanProperties() {
115117
System.clearProperty(PropertiesConfig.CREATE_EXCHANGE_IF_NOT_EXISTING);
116118
System.clearProperty(PropertiesConfig.DOMAIN_ID);
117119
System.clearProperty(PropertiesConfig.CHANNELS_COUNT);
120+
System.clearProperty(PropertiesConfig.TCP_TIMEOUT);
118121
System.clearProperty(PropertiesConfig.WAIT_FOR_CONFIRMS_TIME_OUT);
119122
}
120123

@@ -178,6 +181,7 @@ public void testConnection() throws RemRemPublishException {
178181
String tlsVersion = "1.0";
179182
String exchangeNameTest = "EN2";
180183
String usePersistenceTest = "false";
184+
Integer tcpTimeOut = 5000;
181185
Long waitForConfirmsTimeOut = 5000L;
182186

183187
System.setProperty(PropertiesConfig.MESSAGE_BUS_HOST, host);
@@ -186,6 +190,7 @@ public void testConnection() throws RemRemPublishException {
186190
System.setProperty(PropertiesConfig.TLS, tlsVersion);
187191
System.setProperty(PropertiesConfig.EXCHANGE_NAME, exchangeNameTest);
188192
System.setProperty(PropertiesConfig.USE_PERSISTENCE, usePersistenceTest);
193+
System.setProperty(PropertiesConfig.TCP_TIMEOUT, Integer.toString(tcpTimeOut));
189194
System.setProperty(PropertiesConfig.WAIT_FOR_CONFIRMS_TIME_OUT, Long.toString(waitForConfirmsTimeOut));
190195

191196
RMQHelper rmqHelperTest = new RMQHelper();
@@ -217,14 +222,15 @@ public void testConnection() throws RemRemPublishException {
217222
e.printStackTrace();
218223
assertTrue(false);
219224
}
220-
225+
221226
RabbitMqProperties rabbitmqProtocolPropertiesTest = rmqHelperTest.getRabbitMqPropertiesMap().get(protocol);
222227
assertEquals(host, rabbitmqProtocolPropertiesTest.getHost());
223228
assertEquals(portNumber, rabbitmqProtocolPropertiesTest.getPort());
224229
assertEquals(virtHost, rabbitmqProtocolPropertiesTest.getVirtualHost());
225230
assertEquals(tlsVersion, rabbitmqProtocolPropertiesTest.getTlsVer());
226231
assertEquals(exchangeNameTest, rabbitmqProtocolPropertiesTest.getExchangeName());
227232
assertEquals(waitForConfirmsTimeOut, rabbitmqProtocolPropertiesTest.getWaitForConfirmsTimeOut());
233+
assertEquals(tcpTimeOut, rabbitmqProtocolPropertiesTest.getTcpTimeOut());
228234
}
229235

230236
@Test

publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/config/SecurityConfig.java

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@
1414
*/
1515
package com.ericsson.eiffel.remrem.publish.config;
1616

17+
import java.util.HashMap;
18+
1719
import org.slf4j.Logger;
1820
import org.slf4j.LoggerFactory;
21+
import org.springframework.beans.factory.annotation.Autowired;
1922
import org.springframework.beans.factory.annotation.Value;
2023
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
24+
import org.springframework.context.annotation.Bean;
2125
import org.springframework.context.annotation.Configuration;
2226
import org.springframework.context.annotation.Profile;
27+
import org.springframework.ldap.core.support.BaseLdapPathContextSource;
28+
import org.springframework.ldap.core.support.LdapContextSource;
2329
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
2430
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
2531
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
@@ -52,25 +58,46 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
5258

5359
@Value("${activedirectory.userSearchFilter}")
5460
private String userSearchFilter;
55-
61+
5662
@Value("${activedirectory.rootDn}")
5763
private String rootDn;
5864

59-
@Override
60-
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
65+
@Value("${activedirectory.connectionTimeOut:#{127000}}")
66+
private Integer ldapTimeOut = DEFAULT_LDAP_CONNECTION_TIMEOUT;
67+
68+
// built in connection timeout value for ldap if the network issue happens
69+
public static final Integer DEFAULT_LDAP_CONNECTION_TIMEOUT = 127000;
70+
71+
public Integer getTimeOut() {
72+
return ldapTimeOut;
73+
}
74+
75+
@Autowired
76+
protected void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
6177
final String jasyptKey = RabbitMqPropertiesConfig.readJasyptKeyFile(jasyptKeyFilePath);
6278
if (managerPassword.startsWith("{ENC(") && managerPassword.endsWith("}")) {
6379
managerPassword = DecryptionUtils.decryptString(managerPassword.substring(1, managerPassword.length() - 1), jasyptKey);
6480
}
65-
LOGGER.debug("LDAP server url: "+ldapUrl);
66-
auth.ldapAuthentication().userSearchFilter(userSearchFilter).contextSource().managerDn(managerDn).root(rootDn)
67-
.managerPassword(managerPassword).url(ldapUrl);
81+
LOGGER.debug("LDAP server url: " + ldapUrl);
82+
auth.ldapAuthentication().userSearchFilter(userSearchFilter).contextSource(ldapContextSource());
83+
}
84+
85+
@Bean
86+
public BaseLdapPathContextSource ldapContextSource() {
87+
LdapContextSource ldap = new LdapContextSource();
88+
ldap.setUrl(ldapUrl);
89+
ldap.setBase(rootDn);
90+
ldap.setUserDn(managerDn);
91+
ldap.setPassword(managerPassword);
92+
HashMap<String, Object> environment = new HashMap<>();
93+
environment.put("com.sun.jndi.ldap.connect.timeout", Integer.toString(getTimeOut()));
94+
ldap.setBaseEnvironmentProperties(environment);
95+
return ldap;
6896
}
6997

7098
@Override
7199
protected void configure(HttpSecurity http) throws Exception {
72100
LOGGER.debug("LDAP authentication enabled");
73101
http.authorizeRequests().anyRequest().authenticated().and().httpBasic().and().csrf().disable();
74-
75102
}
76103
}

publish-service/src/main/resources/application.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jasypt.encryptor.jasyptKeyFilePath: <The location of the key which was used to e
1717
#rabbitmq.host=http://127.0.0.1
1818
# must exist
1919
#rabbitmq.exchange.name=eiffel.xxx
20-
rabbitmq.instances.jsonlist=[{ "mp": "eiffelsemantics", "host": "127.0.0.1", "port": "5672", "virtualHost": "", "username": "guest", "password": "guest", "tls": "", "exchangeName": "ertest1234", "channelsCount": "1", "domainId": "eiffelxxx", "createExchangeIfNotExisting":true,"waitForConfirmsTimeOut":"5000"}, \
21-
{ "mp": "eiffel3", "host": "127.0.0.1", "port": "5672", "virtualHost": "", "username": "guest", "password": "guest", "tls": "", "exchangeName": "eiffel3", "domainId": "eiffelxxx", "channelsCount": "1", "createExchangeIfNotExisting":true,"waitForConfirmsTimeOut":"5000" }]
20+
rabbitmq.instances.jsonlist=[{ "mp": "eiffelsemantics", "host": "127.0.0.1", "port": "5672", "virtualHost": "", "username": "guest", "password": "guest", "tls": "", "exchangeName": "ertest1234", "channelsCount": "1", "domainId": "eiffelxxx", "createExchangeIfNotExisting":true,"waitForConfirmsTimeOut":"5000", "tcpTimeOut": "5000" }, \
21+
{ "mp": "eiffel3", "host": "127.0.0.1", "port": "5672", "virtualHost": "", "username": "guest", "password": "guest", "tls": "", "exchangeName": "eiffel3", "domainId": "eiffelxxx", "channelsCount": "1", "createExchangeIfNotExisting":true,"waitForConfirmsTimeOut":"5000", "tcpTimeOut": "5000" }]
2222

2323

2424
# properties for server used to generate messages
@@ -35,3 +35,4 @@ activedirectory.managerPassword : {ENC(<encrypted password>)} or password
3535
activedirectory.managerDn:
3636
activedirectory.rootDn:
3737
activedirectory.userSearchFilter:
38+
activedirectory.connectionTimeOut:

0 commit comments

Comments
 (0)