diff options
author | Michael Lando <ml636r@att.com> | 2018-01-08 10:52:07 +0200 |
---|---|---|
committer | Michael Lando <ml636r@att.com> | 2018-01-08 13:43:07 +0000 |
commit | 50ffa6b75d42f85bd0594e1306677eb11fb47a2c (patch) | |
tree | df675afef0205117f7c1d4e3c1e52c68ca2db5f4 /catalog-dao/src | |
parent | 6f0d1e2de4bfba8c203b81c0e055c0b8c5e79060 (diff) |
expose timeout setting
expose setting of time out in env.json
remove the hard codeing of password in the configuration,
cs password is set using the envjson.
Change-Id: I09cc1f99914f444900e6b73d2ae438c72527ba2c
Issue-ID: SDC-833
Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-dao/src')
-rw-r--r-- | catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraClient.java | 31 | ||||
-rw-r--r-- | catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java | 14 |
2 files changed, 40 insertions, 5 deletions
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraClient.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraClient.java index 38606d00e9..eff094a3a0 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraClient.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraClient.java @@ -24,7 +24,9 @@ import java.util.List; import javax.annotation.PreDestroy; +import com.datastax.driver.core.SocketOptions; import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.config.Configuration; import org.openecomp.sdc.be.config.ConfigurationManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,23 +50,27 @@ public class CassandraClient { private Cluster cluster; private boolean isConnected; + private Configuration.CassandrConfig configuration; public CassandraClient() { super(); isConnected = false; List<String> cassandraHosts = null; try { - cassandraHosts = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig() - .getCassandraHosts(); - Long reconnectTimeout = ConfigurationManager.getConfigurationManager().getConfiguration() - .getCassandraConfig().getReconnectTimeout(); + + this.configuration = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig(); + cassandraHosts = configuration.getCassandraHosts(); + Long reconnectTimeout = configuration.getReconnectTimeout(); + logger.debug("creating cluster to hosts:{} with reconnect timeout:{}", cassandraHosts, reconnectTimeout); Cluster.Builder clusterBuilder = Cluster.builder() .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectTimeout)) .withRetryPolicy(DefaultRetryPolicy.INSTANCE); + cassandraHosts.forEach(host -> clusterBuilder.addContactPoint(host)); + setSocketOptions(clusterBuilder); enableAuthentication(clusterBuilder); enableSsl(clusterBuilder); setLocalDc(clusterBuilder); @@ -78,11 +84,26 @@ public class CassandraClient { logger.info("** CassandraClient created"); } + private void setSocketOptions(Cluster.Builder clusterBuilder) { + SocketOptions socketOptions =new SocketOptions(); + Integer socketConnectTimeout = this.configuration.getSocketConnectTimeout(); + if( socketConnectTimeout!=null ){ + logger.info("SocketConnectTimeout was provided, setting Cassandra client to use SocketConnectTimeout: {} .",socketConnectTimeout); + socketOptions.setConnectTimeoutMillis(socketConnectTimeout); + } + Integer socketReadTimeout = this.configuration.getSocketReadTimeout(); + if( socketReadTimeout != null ){ + logger.info("SocketReadTimeout was provided, setting Cassandra client to use SocketReadTimeout: {} .",socketReadTimeout); + socketOptions.setReadTimeoutMillis(socketReadTimeout); + } + clusterBuilder.withSocketOptions(socketOptions); + } + private void setLocalDc(Cluster.Builder clusterBuilder) { String localDataCenter = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig() .getLocalDataCenter(); if (localDataCenter != null) { - logger.info("localDatacenter was provided, setting Cassndra clint to use datacenter: {} as local.", + logger.info("localDatacenter was provided, setting Cassandra client to use datacenter: {} as local.", localDataCenter); LoadBalancingPolicy tokenAwarePolicy = new TokenAwarePolicy( DCAwareRoundRobinPolicy.builder().withLocalDc(localDataCenter).build()); diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java index e1e33871b1..4de57ded64 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java @@ -22,6 +22,7 @@ package org.openecomp.sdc.be.dao.cassandra.schema; import java.util.List; +import com.datastax.driver.core.SocketOptions; import org.openecomp.sdc.be.config.ConfigurationManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -73,6 +74,19 @@ public class SdcSchemaUtils { System.setProperty("javax.net.ssl.trustStorePassword", truststorePassword); clusterBuilder.withSSL(); } + + SocketOptions socketOptions =new SocketOptions(); + Integer socketConnectTimeout = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig().getSocketConnectTimeout(); + if( socketConnectTimeout!=null ){ + log.info("SocketConnectTimeout was provided, setting Cassandra client to use SocketConnectTimeout: {} .",socketConnectTimeout); + socketOptions.setConnectTimeoutMillis(socketConnectTimeout); + } + Integer socketReadTimeout = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig().getSocketReadTimeout(); + if( socketReadTimeout != null ){ + log.info("SocketReadTimeout was provided, setting Cassandra client to use SocketReadTimeout: {} .",socketReadTimeout); + socketOptions.setReadTimeoutMillis(socketReadTimeout); + } + clusterBuilder.withSocketOptions(socketOptions); return clusterBuilder.build(); } |