diff options
16 files changed, 132 insertions, 51 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(); } diff --git a/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java b/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java index 79d6438df3..0a0d6e505e 100644 --- a/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java +++ b/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java @@ -597,6 +597,8 @@ public class Configuration extends BasicConfiguration { List<String> cassandraHosts; String localDataCenter; Long reconnectTimeout; + Integer socketReadTimeout; + Integer socketConnectTimeout; List<KeyspaceConfig> keySpaces; boolean authenticate; String username; @@ -669,6 +671,14 @@ public class Configuration extends BasicConfiguration { this.reconnectTimeout = reconnectTimeout; } + public Integer getSocketReadTimeout() { return socketReadTimeout; } + + public void setSocketReadTimeout(Integer socketReadTimeout) { this.socketReadTimeout = socketReadTimeout;} + + public Integer getSocketConnectTimeout() { return socketConnectTimeout;} + + public void setSocketConnectTimeout(Integer socketConnectTimeout) { this.socketConnectTimeout = socketConnectTimeout; } + public List<String> getCassandraHosts() { return cassandraHosts; } diff --git a/sdc-os-chef/environments/Template.json b/sdc-os-chef/environments/Template.json index 6052d6806e..d184712a4d 100644 --- a/sdc-os-chef/environments/Template.json +++ b/sdc-os-chef/environments/Template.json @@ -85,7 +85,10 @@ "cache_dir": "/var/lib/cassandra/saved_caches", "log_file": "/var/lib/cassandra/log/system.log", "phi_convict_threshold": "8", - "commitlog_dir": "/var/lib/cassandra/commitlog" + "commitlog_dir": "/var/lib/cassandra/commitlog", + "socket_read_timeout": "20000", + "socket_connect_timeout": "20000", + "titan_connection_timeout": "10000" } } } diff --git a/sdc-os-chef/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/recipes/BE_2_setup_configuration.rb b/sdc-os-chef/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/recipes/BE_2_setup_configuration.rb index baee9d97dc..fde367da7c 100644 --- a/sdc-os-chef/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/recipes/BE_2_setup_configuration.rb +++ b/sdc-os-chef/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/recipes/BE_2_setup_configuration.rb @@ -8,11 +8,12 @@ template "titan.properties" do group "jetty" mode "0755" variables({ - :CASSANDRA_IP => node['Nodes']['CS'], - :CASSANDRA_PWD => node['cassandra'][:cassandra_password], - :CASSANDRA_USR => node['cassandra'][:cassandra_user], - :rep_factor => replication_factor, - :DC_NAME => node['cassandra'][:cluster_name]+node.chef_environment + :CASSANDRA_IP => node['Nodes']['CS'], + :CASSANDRA_PWD => node['cassandra'][:cassandra_password], + :CASSANDRA_USR => node['cassandra'][:cassandra_user], + :rep_factor => replication_factor, + :DC_NAME => node['cassandra'][:cluster_name]+node.chef_environment, + :titan_connection_timeout => node['cassandra']['titan_connection_timeout'] }) end @@ -24,13 +25,18 @@ template "catalog-be-config" do group "jetty" mode "0755" variables({ - :catalog_ip => node['HOST_IP'], - :catalog_port => node['BE'][:http_port], - :ssl_port => node['BE'][:https_port], - :cassandra_ip => node['Nodes']['CS'], - :rep_factor => 1, - :DC_NAME => node['cassandra'][:cluster_name]+node.chef_environment, - :titan_Path => "/var/lib/jetty/config/catalog-be/" + :catalog_ip => node['HOST_IP'], + :catalog_port => node['BE'][:http_port], + :ssl_port => node['BE'][:https_port], + :cassandra_ip => node['Nodes']['CS'], + :rep_factor => 1, + :DC_NAME => node['cassandra'][:cluster_name]+node.chef_environment, + :titan_Path => "/var/lib/jetty/config/catalog-be/", + :socket_connect_timeout => node['cassandra']['socket_connect_timeout'], + :socket_read_timeout => node['cassandra']['socket_read_timeout'], + :cassandra_pwd => node['cassandra'][:cassandra_password], + :cassandra_usr => node['cassandra'][:cassandra_user] + }) end diff --git a/sdc-os-chef/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb b/sdc-os-chef/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb index 9ed32d2939..825dd54061 100644 --- a/sdc-os-chef/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb +++ b/sdc-os-chef/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb @@ -72,9 +72,11 @@ cassandraConfig: cassandraHosts: [<%= @cassandra_ip %>] localDataCenter: <%= @DC_NAME %> reconnectTimeout : 30000 + socketReadTimeout: <%= @socket_read_timeout %> + socketConnectTimeout: <%= @socket_connect_timeout %> authenticate: true - username: asdc_user - password: Aa1234%^! + username: <%= @cassandra_usr %> + password: <%= @cassandra_pwd %> ssl: false truststorePath : /config/.truststore truststorePassword : Aa123456 diff --git a/sdc-os-chef/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-titan.properties.erb b/sdc-os-chef/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-titan.properties.erb index 18b69b3970..cf885e62bb 100644 --- a/sdc-os-chef/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-titan.properties.erb +++ b/sdc-os-chef/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-titan.properties.erb @@ -3,7 +3,7 @@ storage.hostname=<%= @CASSANDRA_IP %> storage.port=9160 storage.username=<%= @CASSANDRA_USR %> storage.password=<%= @CASSANDRA_PWD %> -storage.connection-timeout=10000 +storage.connection-timeout=<%= @titan_connection_timeout %> storage.cassandra.keyspace=sdctitan storage.cassandra.ssl.enabled=false diff --git a/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/recipes/02-createCsUser.rb b/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/recipes/02-createCsUser.rb index 1ebc80d5e4..d9041f2841 100644 --- a/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/recipes/02-createCsUser.rb +++ b/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/recipes/02-createCsUser.rb @@ -3,7 +3,9 @@ template "/tmp/create_cassandra_user.sh" do sensitive true mode 0755 variables({ - :cassandra_ip => "HOSTIP" + :cassandra_ip => "HOSTIP", + :cassandra_pwd => node['cassandra'][:cassandra_password], + :cassandra_usr => node['cassandra'][:cassandra_user] }) end diff --git a/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/recipes/03-createDoxKeyspace.rb b/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/recipes/03-createDoxKeyspace.rb index 789f658694..4e37d49ee0 100644 --- a/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/recipes/03-createDoxKeyspace.rb +++ b/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/recipes/03-createDoxKeyspace.rb @@ -4,7 +4,9 @@ template "/tmp/create_dox_keyspace.sh" do mode 0755 variables({ :cassandra_ip => "HOSTIP", - :DC_NAME => node['cassandra'][:cluster_name]+node.chef_environment + :DC_NAME => node['cassandra'][:cluster_name]+node.chef_environment, + :cassandra_pwd => node['cassandra'][:cassandra_password], + :cassandra_usr => node['cassandra'][:cassandra_user] }) end diff --git a/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/recipes/04-schemaCreation.rb b/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/recipes/04-schemaCreation.rb index 5890603829..0bb0027325 100644 --- a/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/recipes/04-schemaCreation.rb +++ b/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/recipes/04-schemaCreation.rb @@ -18,7 +18,10 @@ template "titan.properties" do source "titan.properties.erb" mode "0755" variables({ - :DC_NAME => node['cassandra'][:cluster_name]+node.chef_environment + :DC_NAME => node['cassandra'][:cluster_name]+node.chef_environment, + :cassandra_pwd => node['cassandra'][:cassandra_password], + :cassandra_usr => node['cassandra'][:cassandra_user], + :titan_connection_timeout => node['cassandra']['titan_connection_timeout'] }) end @@ -28,13 +31,17 @@ template "/tmp/sdctool/config/configuration.yaml" do source "configuration.yaml.erb" mode 0755 variables({ - :host_ip => node['HOST_IP'], - :catalog_port => node['BE'][:http_port], - :ssl_port => node['BE'][:https_port], - :cassandra_ip => node['Nodes']['CS'], - :rep_factor => 1, - :DC_NAME => node['cassandra'][:cluster_name]+node.chef_environment, - :titan_Path => "/tmp/sdctool/config/" + :host_ip => node['HOST_IP'], + :catalog_port => node['BE'][:http_port], + :ssl_port => node['BE'][:https_port], + :cassandra_ip => node['Nodes']['CS'], + :rep_factor => 1, + :DC_NAME => node['cassandra'][:cluster_name]+node.chef_environment, + :titan_Path => "/tmp/sdctool/config/", + :socket_connect_timeout => node['cassandra']['socket_connect_timeout'], + :socket_read_timeout => node['cassandra']['socket_read_timeout'], + :cassandra_pwd => node['cassandra'][:cassandra_password], + :cassandra_usr => node['cassandra'][:cassandra_user] }) end diff --git a/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/recipes/05-titanSchemaCreation.rb b/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/recipes/05-titanSchemaCreation.rb index a3af2f490f..fa9ae79690 100644 --- a/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/recipes/05-titanSchemaCreation.rb +++ b/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/recipes/05-titanSchemaCreation.rb @@ -19,7 +19,10 @@ template "titan.properties" do source "titan.properties.erb" mode "0755" variables({ - :DC_NAME => node['cassandra'][:cluster_name]+node.chef_environment + :DC_NAME => node['cassandra'][:cluster_name]+node.chef_environment, + :cassandra_pwd => node['cassandra'][:cassandra_password], + :cassandra_usr => node['cassandra'][:cassandra_user], + :titan_connection_timeout => node['cassandra']['titan_connection_timeout'] }) end @@ -29,13 +32,17 @@ template "/tmp/sdctool/config/configuration.yaml" do source "configuration.yaml.erb" mode 0755 variables({ - :host_ip => node['HOST_IP'], - :catalog_port => node['BE'][:http_port], - :ssl_port => node['BE'][:https_port], - :cassandra_ip => node['Nodes']['CS'], - :rep_factor => 1, - :DC_NAME => node['cassandra'][:cluster_name]+node.chef_environment, - :titan_Path => "/tmp/sdctool/config" + :host_ip => node['HOST_IP'], + :catalog_port => node['BE'][:http_port], + :ssl_port => node['BE'][:https_port], + :cassandra_ip => node['Nodes']['CS'], + :rep_factor => 1, + :DC_NAME => node['cassandra'][:cluster_name]+node.chef_environment, + :titan_Path => "/tmp/sdctool/config", + :socket_connect_timeout => node['cassandra']['socket_connect_timeout'], + :socket_read_timeout => node['cassandra']['socket_read_timeout'], + :cassandra_pwd => node['cassandra'][:cassandra_password], + :cassandra_usr => node['cassandra'][:cassandra_user] }) end diff --git a/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/configuration.yaml.erb b/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/configuration.yaml.erb index 03a5bfbae5..f99737b0f9 100644 --- a/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/configuration.yaml.erb +++ b/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/configuration.yaml.erb @@ -70,6 +70,8 @@ cassandraConfig: cassandraHosts: [<%= @cassandra_ip %>] localDataCenter: <%= @DC_NAME %> reconnectTimeout : 30000 + socketReadTimeout: <%= @socket_read_timeout %> + socketConnectTimeout: <%= @socket_connect_timeout %> authenticate: true username: asdc_user password: Aa1234%^! diff --git a/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/create_cassandra_user.sh.erb b/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/create_cassandra_user.sh.erb index 6b972244c2..9fcf165f44 100644 --- a/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/create_cassandra_user.sh.erb +++ b/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/create_cassandra_user.sh.erb @@ -1,7 +1,7 @@ #!/bin/bash -CASSANDRA_USER=asdc_user -CASSANDRA_PASS=Aa1234%^! +CASSANDRA_USER=<%= @cassandra_usr %> +CASSANDRA_PASS=<%= @cassandra_pwd %> CASSANDRA_IP=<%= @cassandra_ip %> pass_changed=99 diff --git a/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/create_dox_keyspace.sh.erb b/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/create_dox_keyspace.sh.erb index 37b785970c..e316234d1e 100644 --- a/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/create_dox_keyspace.sh.erb +++ b/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/create_dox_keyspace.sh.erb @@ -1,7 +1,7 @@ #!/bin/bash -CASSANDRA_USER=asdc_user -CASSANDRA_PASS='Aa1234%^!' +CASSANDRA_USER='<%= @cassandra_usr %>' +CASSANDRA_PASS='<%= @cassandra_pwd %>' KEYSPACE="CREATE KEYSPACE IF NOT EXISTS dox WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', '<%= @DC_NAME %>': '1'};" KEYSPACE1="CREATE KEYSPACE IF NOT EXISTS zusammen_dox WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', '<%= @DC_NAME %>': '1'};" diff --git a/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/titan.properties.erb b/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/titan.properties.erb index bccf2210af..6f7859e184 100644 --- a/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/titan.properties.erb +++ b/sdc-os-chef/sdc-cassandra/chef-repo/cookbooks/cassandra-actions/templates/default/titan.properties.erb @@ -1,25 +1,29 @@ storage.backend=cassandra storage.hostname=localhost storage.port=9160 -storage.username=asdc_user -storage.password=Aa1234%^! +storage.username=<%= @cassandra_usr %> +storage.password=<%= @cassandra_pwd %> +storage.connection-timeout=<%= @titan_connection_timeout %> storage.cassandra.keyspace=sdctitan + storage.cassandra.ssl.enabled=false storage.cassandra.ssl.truststore.location=/var/lib/jetty/config/.truststore storage.cassandra.ssl.truststore.password=Aa123456 -cache.db-cache = false -cache.db-cache-clean-wait = 20 -cache.db-cache-time = 180000 -cache.db-cache-size = 0.5 - storage.cassandra.read-consistency-level=LOCAL_QUORUM storage.cassandra.write-consistency-level=LOCAL_QUORUM storage.cassandra.replication-strategy-class=org.apache.cassandra.locator.NetworkTopologyStrategy storage.cassandra.replication-strategy-options=<%= @DC_NAME %>,1 storage.cassandra.astyanax.local-datacenter=<%= @DC_NAME %> +cache.db-cache = false +cache.db-cache-clean-wait = 20 +cache.db-cache-time = 180000 +cache.db-cache-size = 0.5 + +cache.tx-cache-size = 1000000 + storage.lock.retries=5 storage.lock.wait-time=500 diff --git a/sdc-os-chef/sdc-cassandra/startup.sh b/sdc-os-chef/sdc-cassandra/startup.sh index 2f7cc3c53d..49edc26130 100755 --- a/sdc-os-chef/sdc-cassandra/startup.sh +++ b/sdc-os-chef/sdc-cassandra/startup.sh @@ -20,6 +20,7 @@ echo "########### starting cassandra ###########" sleep 10 chef-solo -c solo.rb -E ${CHEFNAME} - +rc=$? +if [[ $rc != 0 ]]; then exit $rc; fi while true; do sleep 2; done |